Copy CodeThe code is as follows:
<title>Login</title>
Copy CodeThe code is as follows:
@mysql_connect ("localhost", "root", "1981427")//Select the database before you need to connect to the database server
Or Die ("Database server Connection Failed");
@mysql_select_db ("test")//Select Database MyDB
Or Die ("database does not exist or is not available");
Get user input
$username = $_post[' username ');
$passcode = $_post[' passcode ');
Execute SQL statement to get the value of session
$query = @mysql_query ("Select Username, userflag from users"
." where username = ' $username ' and passcode = ' $passcode ' ")
Or Die ("SQL statement execution failed");
Determine if the user exists, the password is correct
if ($row = mysql_fetch_array ($query))
{
Session_Start (); The beginning of the sign session
Determines whether the user's permission information is valid, or if 1 or 0 indicates a valid
if ($row [' userflag '] = = 1 or $row [' userflag '] = = 0)
{
$_session[' username '] = $row [' username '];
$_session[' userflag '] = $row [' Userflag '];
echo "Welcome to login, click here to enter the Welcome screen";
}
else//If permission information is invalid output error message
{
echo "User rights information is incorrect";
}
}
else//If the user name and password are incorrect, the output error
{
echo "User name or password error";
}
?>
Copy CodeThe code is as follows:
unset ($_session[' username ');
unset ($_session[' passcode ');
unset ($_session[' Userflag ');
echo "Logout success";
?>
Copy CodeThe code is as follows:
Session_Start ();
if (isset ($_session[' username '))
{
@mysql_connect ("localhost", "root", "1981427")//Select the database before you need to connect to the database server
Or Die ("Database server Connection Failed");
@mysql_select_db ("test")//Select Database MyDB
Or Die ("database does not exist or is not available");
Get session
$username = $_session[' username ');
Execute SQL statement to get Userflag value
$query = @mysql_query ("Select Userflag from Users"
." where username = ' $username ' ")
Or Die ("SQL statement execution failed");
$row = Mysql_fetch_array ($query);
The information in the current database is compared to the information in the session, and if it is different, the session is updated.
if ($row [' userflag ']! = $_session[' Userflag '])
{
$_session[' userflag '] = $row [' Userflag '];
}
Output a different welcome message based on the value of the session
if ($_session[' userflag ') = = 1)
echo "Welcome administrator". $_session[' username '. " Login System ";
if ($_session[' userflag ') = = 0)
echo "Welcome user". $_session[' username ']. " Login System ";
echo "Logout";
}
Else
{
echo "You do not have permission to access this page";
}
?>
http://www.bkjia.com/PHPjc/319892.html www.bkjia.com true http://www.bkjia.com/PHPjc/319892.html techarticle Copy the code code as follows: HTML head titlelogin/title meta http-equiv= "Content-type" content= "text/html; charset=gb2312"/head body F ORM Name= "Form1" method= "Post" action= "login.ph ...