Strange problem with session (already searched, but still can’t solve it myself)
My main login page is to determine whether to log in. Enter the address directly to avoid the login window. The first time it appears, you do not have permission to access, and admin|b:0 appears in the session file; refresh it once, and you have logged in
Notice: Undefined index: name in d:usrwwwhtmldengluindex.php on line 5
111122223333
The file in the session file becomes admin|b:1; the value of admin is 1. Strange! ! !
This is the code for index.php:
$admin=false;
if(isset($_SESSION['admin'])&&$_SESSION['admin']=true)
{ echo "You have logged in";
echo $_SESSION['name'];
}
else
{$_SESSION['admin']=false;
die("You don't have access");
header("Location:login.htm");
}
?>
111122223333
In the previous verification, if the username and password are correct, let $_SESSION['admin'] = true;
This is the login.php code:
$xm=$_POST['xingming'];
$ps=$_POST['password'];
$_SESSION['admin'] = false;
$link = mysql_connect('localhost','root','');
$db = mysql_select_db('hehetsg');
$result = mysql_query("select * from user where user = '$xm' and psw ='$ps'");
if ($row=mysql_fetch_array($result))
{ if ($row['psw']==$ps and $row['flag']==1)
{ $_SESSION['name']=$row['name'];
$_SESSION['admin'] = true;
echo "Welcome to the administrator!";
echo "Management interface";
}
else
{ echo "Not an administrator. Sorry!";
echo "Click to return";
}
}
else { echo "Your information is incomplete!";
echo "Click to return";
}
?>
Enter your login information here:
Login page
[ ]
echo "
";echo "
";echo "
";
High!!!!
It would be better if you help me solve it! ! Haha
Add error_reporting(0);
before session_start()
isset($_SESSION['admin'])&&$_SESSION['admin']=true
It