Комментарии:
The source Code :
login.php
<?php
$host="localhost";
$user="root";
$password="";
$db="user";
session_start();
$data=mysqli_connect($host,$user,$password,$db);
if($data===false)
{
die("connection error");
}
if($_SERVER["REQUEST_METHOD"]=="POST")
{
$username=$_POST["username"];
$password=$_POST["password"];
$sql="select * from login where username='".$username."' AND password='".$password."' ";
$result=mysqli_query($data,$sql);
$row=mysqli_fetch_array($result);
if($row["usertype"]=="user")
{
$_SESSION["username"]=$username;
header("location:userhome.php");
}
elseif($row["usertype"]=="admin")
{
$_SESSION["username"]=$username;
header("location:adminhome.php");
}
else
{
echo "username or password incorrect";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<center>
<h1>Login Form</h1>
<br><br><br><br>
<div style="background-color: grey; width: 500px;">
<br><br>
<form action="#" method="POST">
<div>
<label>username</label>
<input type="text" name="username" required>
</div>
<br><br>
<div>
<label>password</label>
<input type="password" name="password" required>
</div>
<br><br>
<div>
<input type="submit" value="Login">
</div>
</form>
<br><br>
</div>
</center>
</body>
</html>
adminhome.php
<?php
session_start();
if(!isset($_SESSION["username"]))
{
header("location:login.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>THIS IS ADMIN HOME PAGE</h1><?php echo $_SESSION["username"] ?>
<a href="logout.php">Logout</a>
</body>
</html>
userhome.php
<?php
session_start();
if(!isset($_SESSION["username"]))
{
header("location:login.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>THIS IS USER HOME PAGE</h1><?php echo $_SESSION["username"] ?>
<a href="logout.php">Logout</a>
</body>
</html>
logout.php
<?php
session_start();
session_destroy();
header("location:login.php");
?>
Great Tutorial! Thank you!
ОтветитьHow i correct 'Trying to access array offset on value of type null in ...'??????pls give me solution......
ОтветитьThank you so much bro❤
ОтветитьMany Thanks
Ответитьwaste of time the code is running in your system but not working others system
ОтветитьWhy i got this error ??
Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\SIP23PROJECT\User.php on line 25
Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\SIP23PROJECT\User.php on line 30
username or password incorrect
Please kindly help on how i can login to admin password from a database
ОтветитьThank you for this but please, when I login in, I don't see the username displayed
And when I add the Access denied code for non logged in users, even a registered account is redirected to the login page
Can I have this same one done in notepad
Ответитьmen it was good tutorial but if i login as a user and i type the admin homepae url i can go in
Ответитьspent the entire day looking through countless videos to create a login system to no avail. So glad that I found your video! I was able finish the whole thing from scratch within 30 mins. :)
Ответитьelseif($row["usertype"]=="admin")
{
$_SESSION["username"]=$username;
header("location:adminhome.php");
}
PLEASE HELP ME, IM ERROR with that line
it gives this warning "Warning: Trying to access array offset on value of type null"
can we use the same php code and relate it with android studio app please help
Ответитьis it the same for android studio app?
Ответитьthis short video tutorial was really helpful. Thank you.
ОтветитьCan u tell me how can i change the name of the user_type bcs i have done it but the error keeps coming
ОтветитьCan I ask what tools or software I need for programming
Ответитьoke
ОтветитьSIR SHARE CODING
Ответитьhai, any one can be login as user or admin
ОтветитьThank you sooo much🙏🙏
ОтветитьSince you are only checking to see if the username session variable is set, once you login as a regular user, you can then type the URL for the admin home page and gain access.
Ответитьsir everything is easy to understand i like this video it is in full detail
ОтветитьHello, how do I get my xammp port to work, it says port 3306 has been occupied
ОтветитьThank you for sharing your knowledge.
ОтветитьWarning: Trying to access array offset on value of type null in C:\xampp\htdocs\CAPSTONE\loginpractice\login.php on line 31
Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\CAPSTONE\loginpractice\login.php on line 39
Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\CAPSTONE\loginpractice\login.php on line 47
can someone help me with this error asap
Can i request sir ...can you please make an municipal library system sir thank you and godbless
ОтветитьThank you very much my friend its work
Ответитьhello how i can change user to be an admin from backend ?? i know i must make a register page and all data go to database can i know how i make some user be admin not from change his statues from phpmyadmin
ОтветитьPatta machan
ОтветитьI login into the user account, but if I click on the back, the page goes to admin page . any one have solution?
<?php
include 'config.php';
session_start();
if(isset($_SESSION['username'])){
header("Location: 1index.php");
}
if(isset($_POST['submit'])) {
$email = $_POST['email'];
$password = md5($_POST['password']);
$sql = "SELECT * FROM users WHERE email='$email' AND password='$password'";
$result = mysqli_query($conn, $sql);
if ($result->num_rows > 0) {
$row = mysqli_fetch_assoc($result);
if($row["usertype"]=="user")
{
$_SESSION['username'] = $row['username'];
header("location:index.php");
}
elseif($row["usertype"]=="admin")
{
$_SESSION['username'] = $row['username'];
header("Location: 1index.php");
}
} else {
echo "<script>alert('Woops! Email or Password is Wrong.')</script>";
}
}
?>
Thank you!
Ответитьthank your sir this video very helpful 🙏🙏
Ответитьpretty sure after login in as user you can, type in the adminhome.php and have access to that, because theirs no role check so maybe add this:
adminhome.php
<?php
session_start();
if(!($_SESSION["username"] == admin))
{
header("location:login.php");
}
?>
The same for userhome.php.
thank you so much saved my life, liked!
Ответитьhow to fix?
Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\project\login.php on line 31
Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\project\login.php on line 39
goood
ОтветитьThanks * infinity
Ответитьbhai helpfullll
ОтветитьIf its not too much trouble, please do an online crime reporting system, where the police is the admin
ОтветитьYou have taught me alot than my teachers😍😍 thank you so much
ОтветитьIf we use html , javascript and css for front end then will it work ???
ОтветитьIncrível!!! Professor parabéns!
Ответитьcan you teach us how to make attendance app for student plsss🙏🙏
Ответитьadd hw to select data from database
Ответитьthis is really helpful!
ОтветитьAn error in this...... That was... Trying to access array offset on value of type null... Plz give solution
ОтветитьI got this warning "Warning: Trying to access array offset on value of type null" with admin account only, what happening? and what should i do?
thank you