<title>Login</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body>
<form name= "Form1" method= "Post" action= "login.php" >
<table width= "border=" 0 "align=" center "cellpadding=" 2 "cellspacing=" 2 ">
<tr>
<TD width= "><div" align= "right" > Username:</div></td>
<TD width= "><input" type= "text" name= "username" ></td>
</tr>
<tr>
<td><div align= "Right" > Password:</div></td>
<td><input type= "password" name= "passcode" ></td>
</tr>
<tr>
<td><div align= "Right" >cookie save time:</div></td>
<td><select name= "Cookie" id= "Cookie" >
<option value= "0" selected> Browser process </option>
<option value= "1" > Save 1 days </option>
<option value= "2" > Save 30 days </option>
<option value= "3" > Save 365 days </option>
</select></td>
</tr>
</table>
<p align= "center" >
<input type= "Submit" name= "submit" value= "Submit" >
<input type= "reset" name= "reset" value= "reset" >
</p>
</form>
</body>
--------------------------------------------------------------------
<?php
@mysql_connect ("localhost", "root", "1981427")//Select 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 not available");
Get user input
$username = $_post[' username '];
$passcode = $_post[' passcode '];
Execute SQL statement to get the value of the 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 and the password is correct
if ($row = mysql_fetch_array ($query))
{
Session_Start (); Mark the beginning of the session
Determines whether the user's permission information is valid, or if 1 or 0 is valid
if ($row [' userflag '] = = 1 or $row [' userflag '] = = 0)
{
$_session[' username ' = $row [' username '];
$_session[' userflag ' = $row [' Userflag '];
echo "<a href=" main.php "href=" main.php "> Welcome to login, click here to enter the Welcome interface </a>";
}
else//If the permission information is invalid output error message
{
echo "User right information is incorrect";
}
}
else//If the username and password are incorrect, the output error
{
echo "User name or password error";
}
?>
--------------------------------------------------------------
<?php
unset ($_session[' username '));
unset ($_session[' passcode '));
unset ($_session[' Userflag '));
echo "Logout success";
?>
---------------------------------------------------------------
<?php
Session_Start ();
if (isset ($_session[' username '))
{
@mysql_connect ("localhost", "root", "1981427")//Select 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 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 judged by comparison with the message in the session, and the session information is updated if different.
if ($row [' Userflag ']!= $_session[' Userflag '])
{
$_session[' userflag ' = $row [' Userflag '];
}
Output different welcome information according to the session value
if ($_session[' userflag '] = = 1)
echo "Welcome admin". $_session[' username '. " Login System ";
if ($_session[' userflag '] = = 0)
echo "Welcome user". $_session[' username '. " Login System ";
echo "<a href=" logout.php "href=" logout.php "> Logoff </a>";
}
Else
{
echo "You do not have permission to access this page";
}
?> Beginners PHP I also reproduced others, not on the machine test, the first collection of
From: http://phpstart.php100.com/apps-htm-q-diary-a-detail-did-7373.html