Open Dreamweaver CS6 and add the following code:
if ($_post[user])//Determine if user name is entered
{
$name =$_post["User"]; Get login user Name
$pass =$_post["Pass"]; Get login Password
Require "ch16-1.php"; Referencing a configuration file
$link =mysql_connect ($db _host, $db _user, $db _pass) or Die (Mysql_error ());
mysql_select_db ($db _name, $link);
$sql = "SELECT * from $table _user where u_name= ' $name ' && u_pass= ' $pass '";
$result =mysql_query ($sql); Send SQL Request
if (@mysql_num_rows ($result)!=0)//Find eligible users and passwords
{
Setcookie ("name", "$name", Time () +60*60*24); Create a cookie
echo " ";
echo " ";
echo "";
echo "
Login Successful! Back to the back page in 1 seconds ... ";
echo "";
}
else//If there are no eligible users and passwords
{
echo "
The user name or password is wrong! ";
}
}
?>
Administrator Login
@ All rights reserved
at last, save the file and debug the run
Click "File"-"save" or press the shortcut key ctrl+s to save the page with the file name ch16-8.php, the file is automatically saved to the site. Press F12 keyboard to debug the webpage, display:
Enter the user name and password, if successful, then go to the hypervisor: Show graph:
Both,
This example includes the User Login form section and the form's handler, which realizes the user login function.
? The user login function is also a very simple function, it is not difficult to achieve. As long as the input of the user and password is present in the Administrator information table, if present, the login is successful, and the user name is saved to the cookie variable, and automatically jump to the background home page; If no matching administrator information is found, a "username and password Error" is displayed.
This example code is as follows:
if ($_post[user])//Determine if user name is entered
{
$name =$_post["User"]; Get login user Name
$pass =$_post["Pass"]; Get login Password
Require "ch16-1.php"; Referencing a configuration file
$link =mysql_connect ($db _host, $db _user, $db _pass) or Die (Mysql_error ());
mysql_select_db ($db _name, $link);
$sql = "SELECT * from $table _user where u_name= ' $name ' && u_pass= ' $pass '";
$result =mysql_query ($sql); Send SQL Request
if (@mysql_num_rows ($result)!=0)//Find eligible users and passwords
{
Setcookie ("name", "$name", Time () +60*60*24); Creating cookie Variables
echo " ";
echo " ";
echo "";
echo "
Login Successful! Back to the back page in 1 seconds ... ";
echo "";
}
else//If there are no eligible users and passwords
{
echo "
The user name or password is wrong! ";
}
}
In the program using JavaScript code to implement the user name and password two input box, the corresponding code is as follows:
Call the JS function juge () during form submission to validate the entry:
End, you can think in practice.