Common users can log on to the administrator logon page.

Source: Internet
Author: User
The administrator logon interface can also be used by common users. The younger brother is studying PHP and is currently writing a message board and admin. when using this part of php code, you can log on to the account of a common user without knowing 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
 Administrator login
 
 
 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





Reply to discussion (solution)

Add a field admin special identification you can welcome to visit personal php learning website http://www.phpthinking.com

Do I enclose admin in single quotes? Or .....

You have to log on successfully and save it to the session.

????
1. $ _ SESSION ['User _ name'] = $ user_name ;? Sentence ?? After successful login? Use
2. Common use ?? Management? Are all judged by $ _ SESSION ['User _ name? Log on ,?? Common use? What can I do after I log on? Management? Logon all? Login ?? .
?? Manage? Log on to save? To $ _ SESSION ['admin _ user_name '] under management? ? Entered? Face, judge? $ _ SESSION ['admin _ user_name '] instead of $ _ SESSION ['User _ name']

Upstairs! If the login succeeds, it will be saved to the session. otherwise, when determining whether the variables in the session exist, it will not be logged on or not. What else should I log on.

????
1. $ _ SESSION ['User _ name'] = $ user_name ;? Sentence ?? After successful login? Use
2. Common use ?? Management? Are all judged by $ _ SESSION ['User _ name? Log on ,?? Common use? What can I do after I log on? Management? Logon all? Login ?? .
?? Manage? Log on to save? To $ _ SESSION ['admin _ user_name '] under management? ? Entered? Face, judge? $ _ SESSION ['admin _ user_name '] instead of $ _ SESSION ['User _ name']

After successfully logging on to the console, add $ _ SESSION ['admin _ user_name '] = $ user_name. the management interface cannot be found .. The previous session start is removed.


????
1. $ _ SESSION ['User _ name'] = $ user_name ;? Sentence ?? After successful login? Use
2. Common use ?? Management? Are all judged by $ _ SESSION ['User _ name? Log on ,?? Common use? What can I do after I log on? Management? Logon all? Login ?? .
?? Manage? Log on to save? To $ _ SESSION ['admin _ user_name '] under management? ? Entered? Face, judge? $ _ SESSION ['admin _ user_name '] instead of $ _ SESSION ['User _ name']

After successfully logging on to the console, add $ _ SESSION ['admin _ user_name '] = $ user_name. the management interface cannot be found .. The previous session start is removed.




????
1. $ _ SESSION ['User _ name'] = $ user_name ;? Sentence ?? After successful login? Use
2. Common use ?? Management? Are all judged by $ _ SESSION ['User _ name? Log on ,?? Common use? What can I do after I log on? Management? Logon all? Login ?? .
?? Manage? Log on to save? To $ _ SESSION ['admin _ user_name '] under management? ? Entered? Face, judge? $ _ SESSION ['admin _ user_name '] instead of $ _ SESSION ['User _ name']

After successfully logging on to the console, add $ _ SESSION ['admin _ user_name '] = $ user_name. the management interface cannot be found .. The previous session start is removed.

Now, no matter what user name or password I enter, can I log on? What's wrong ??



????
1. $ _ SESSION ['User _ name'] = $ user_name ;? Sentence ?? After successful login? Use
2. Common use ?? Management? Are all judged by $ _ SESSION ['User _ name? Log on ,?? Common use? What can I do after I log on? Management? Logon all? Login ?? .
?? Manage? Log on to save? To $ _ SESSION ['admin _ user_name '] under management? ? Entered? Face, judge? $ _ SESSION ['admin _ user_name '] instead of $ _ SESSION ['User _ name']

After successfully logging on to the console, add $ _ SESSION ['admin _ user_name '] = $ user_name. the management interface cannot be found .. The previous session start is removed.




????
1. $ _ SESSION ['User _ name'] = $ user_name ;? Sentence ?? After successful login? Use
2. Common use ?? Management? Are all judged by $ _ SESSION ['User _ name? Log on ,?? Common use? What can I do after I log on? Management? Logon all? Login ?? .
?? Manage? Log on to save? To $ _ SESSION ['admin _ user_name '] under management? ? Entered? Face, judge? $ _ SESSION ['admin _ user_name '] instead of $ _ SESSION ['User _ name']

After successfully logging on to the console, add $ _ SESSION ['admin _ user_name '] = $ user_name. the management interface cannot be found .. The previous session start is removed.

Now, no matter what user name or password I enter, can I log on? What's wrong ??

Wrong. now, no matter what you enter, the js logon success box is displayed, and the logon interface is returned.

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.