You can also log on to the administrator logon page.

Source: Internet
Author: User
On the administrator logon page, common users can also log on to this post. at last, yoshikis learned PHP by the editing younger brother at 2014-09-1811: 55: 57. Currently, a message board and admin are written. when using this part of php code, you can log on to the account of a common user without knowing what went wrong. My SQL statement selects the admin table. Why can I log on to the admin table even if the user in the user table can select the administrator?

This post was last edited by yoshikis at 11:55:57 on

The younger brother is studying PHP by himself. He is currently writing a message board. when writing admin. php code, he can log on to the account of a common user. he does not know what went wrong. I selected the admin table for the SQL statement. Why can I select the admin table even for users in the user table? Don't understand, please answer.

Admin. php code
 Error_reporting (0 );
@ Session_start ();
Require_once 'Conn/conn. php ';
$ User_name = $ _ POST ['name'];
$ Password = md5 ($ _ POST ['password']);
$ _ SESSION ['User _ name'] = $ user_name;
If (strlen ($ user_name) <1 ){
?>


Administrator login








}
Else if (strlen ($ user_name)> 1 ){
$ Query = "select * from admin where user_name =? And password =? ";
// Echo $ query;
// Exit;
$ St = $ db-> prepare ($ query );
$ Rs = $ st-> execute (array ($ user_name, $ password ));
If ($ rs = false)
{

Echo" Script alert ('login failed! '); Window. location. href = 'admin. php' script ";
}
Else
{
// Echo "login successful! ";
Echo" Script alert ('Administrator login successful! '); Window. location. href = 'admin _ select_neirong.php' script ";
}
}

?>



Table structure

Admin table


User table





------ Solution ----------------------
Two questions
1. $ _ SESSION ['User _ name'] = $ user_name; this statement should be used after logon.
2. common users and administrators use $ _ SESSION ['User _ name'] to determine whether to log on to the queue, it is determined that all logon attempts by administrators will be successful.
The administrator's login should be saved as $ _ SESSION ['admin _ user_name '] on the administrator's login plane, sentence $ _ SESSION ['admin _ user_name '] instead of $ _ SESSION ['User _ name']

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.