PHP Authentication login user name and password

Source: Internet
Author: User
This article is to tell you about the use PHPUser name and password verification, detailed explanation of the PHPHow to connect the database and how to query data from the database and verify, I hope we can learn PHPBring help.

Login Page

Login.html is responsible for collecting user-filled login information


Login Processing
Login.php is responsible for handling user login and exit actions.

<?php//Login if (!isset ($_post[' submit ')) {exit (' illegal access! ');  } $username = Htmlspecialchars ($_post[' username ');    $password = MD5 ($_post[' password ');  Contains the database connection file include (' conn.php '); Detects if the user name and password are correct $check _query = mysql_query ("Select UserID from User_list where username= ' $username ' and password= ' $passwo  Rd ' limit 1 ');      if ($result = mysql_fetch_array ($check _query)) {//Login succeeded Session_Start ();      $_session[' username '] = $username;      $_session[' userid '] = $result [' userid ']; echo $username, ' Welcome!      Enter <a href= "my.php" > User Center </a><br/> '; Echo ' Click here <a href= "Login.php?action=logout" > Logout </a> Login!      <br/> ';  Exit } else {exit (' Login failed! Click here <a href= "Javascript:history.back (-1);"  > Return </a> retry ');      }//Logout login if ($_get[' action '] = = "Logout") {unset ($_session[' userid ');      unset ($_session[' username '); Echo ' Logout login succeeded!      Click here <a href= "login.html" > Login </a> ";  Exit }?>

User Center
my.php is the user Center, which is detected as a user login.

<?php  session_start ();    Check whether to log in, if not login to the login interface if  (!isset ($_session[' userid ')) {      header ("Location:login.html");      Exit ();  }  Contains the database connection file  include (' conn.php ');  $userid = $_session[' userid '];  $username = $_session[' username ');  $user _query = mysql_query ("select * from user_list where UserID = ' $userid ' limit 1");  $row = mysql_fetch_array ($user _query);  Echo ' User information: <br/> ';  echo ' User id: ', $userid, ' <br/> ';  Echo ' username: ', $username, ' <br/> ';  Echo ' <a href= "login.php?action=logout" > Logout </a> login <br/> ';  ? >

conn.php for connecting to the database

<?php      $conn = mysql_connect ("127.0.0.1", "Root", "") or Die ("Database link Error". mysql_error ());   mysql_select_db ("info_db", $conn) or Die ("Database access Error". Mysql_error ());   mysql_query ("Set names gb2312");  ? >

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.