Session's strange problem (I have searched and cannot solve it myself)
On the my login homepage, I used to determine whether to log in. I directly entered the address to repeat the login window. The first time you see that you have no access permission, the session file shows admin | B: 0; refresh once, you have logged on
Notice: Undefined index: name in d: usrwwwhtmldengluindex. php on line 5
111122223333
The file in the session file becomes admin | B: 1; the admin value is 1. Strange !!!
This is the index. php code:
$ Admin = false;
If (isset ($ _ SESSION ['admin']) & $ _ SESSION ['admin'] = true)
{Echo "you have logged on ";
Echo $ _ SESSION ['name'];
}
Else
{$ _ SESSION ['admin'] = false;
Die ("You are not authorized to access ");
Header ("Location: login.htm ");
}
?>
111122223333
In the previous verification, if the user name and password are correct, set $ _ SESSION ['admin'] to 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 ('hetsg ');
$ 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 "is not an administrator. Sorry! ";
Echo "Click Back ";
}
}
Else {echo "your information is incomplete! ";
Echo "Click Back ";
}
?>
Enter the login information here:
Login Page
[]
Echo"
"; Echo"
"; Echo"
";
High !!!!!
Help me solve the problem !! Haha
Add error_reporting (0) before session_start );
Isset ($ _ SESSION ['admin']) & $ _ SESSION ['admin'] = true
It is a logical error.
Original Post published on July 15 at [url = http://www.111cn.cn/bbs/redirect.php? Goto = findpost & pid = 505295 & ptid = 70090] link mark [img] http://www.111cn.cn/bbs/images/common/back.gif?/img=#/url]
Add error_reporting (0) before session_start );
Thanks, ......
I added this, so there is no error, but I still cannot verify it.
The login fails and becomes an administrator login.
Verification is meaningless.
Original Post published by dongxin1390008 at [url = http://www.111cn.cn/bbs/redirect.php? Goto = findpost & pid = 505300 & ptid = 70090] link mark [img] http://www.111cn.cn/bbs/images/common/back.gif?/img=#/url]
Isset ($ _ SESSION ['admin']) & $ _ SESSION ['admin'] = true
It is a logical error.
So how should we write it correctly?
Die ("You are not authorized to access ");
Header ("Location: login.htm ");
There are also problems here
No output exists before the header.
Logical equals two equal signs. The value assignment is an equal sign,
Isset ($ _ SESSION ['admin']) & $ _ SESSION ['admin'] = true
As long as the $ _ SESSION ["admin"] is not empty
Correct:
Isset ($ _ SESSION ['admin']) & $ _ SESSION ['admin'] = true
Can you post the correct code?
Help beginners,
Very grateful