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"); ? >