Here we want to talk about two kinds of user login methods is to use window validation Plus database tutorial Password Authentication implementation login, the latter is the use of cookies to record user information to log in, the need for friends can try.
<?php Tutorial
function Authenticate_user () {
Header (' Www-authenticate:basic realm= "Secret Stash");
Header ("http/1.0 401 Unauthorized");
Exit
}
if (! isset ($_server[' Php_auth_user ')) {
Authenticate_user ();
} else {
MySQL tutorial _pconnect ("localhost", "authenticator", "secret") or Die ("Can ' t connect to Database server!");
mysql_select_db ("Java2s") or Die ("Can ' t select Authentication database!");
$query = "Select Username, PS Tutorial wd from user WHERE username= ' $_server[php_auth_user] ' and PSWD=MD5 (' $_SERVER[PHP_AUTH_PW] ')";
$result = mysql_query ($query);
If Nothing is found, reprompt the user for the login www.111cn.net information.
if (mysql_num_rows ($result) = = 0) {
Authenticate_user ();
}
}
?>
Using Cookies to login methods
<title>enter password</title>
<body>
<form name= "Forml" method= "POST" action= "cookiebasedpasswordlogin.php" >
<table>
<tr>
<TD colspan= "2" >
<div align= "center" ><b>please Specify the Password</b></div>
</td>
</tr>
<tr>>
<td>
<div align= "right" >customer id</div>
</td>
<td>
<input type= "text" name= "username" >
</td>
</tr>
<tr>
<td>
<div align= "right" >Password</div>
</td>
<td>
<input type= "password" name= "password" >
</td>
</tr>
<tr>
<TD colspan= "2" >
<center>
<input type= "Submit" name= "Submit" value= "Login" >
</center>
</td>
</tr>
</table>
</form>
</body>
<!--cookiebasedpasswordlogin.php
<?php
$now = getdate ();
$storetime = $now ["Weekday"]. " " . $now ["Month"]. " " . $now ["Year"];
$storetime. = "Time:";
if ($now ["hours"] < 10) {
$storetime. = "0". $now ["hours"];
} else {
$storetime. = $now ["hours"];
}
$storetime. = ":";
if ($now ["Minutes"]<10) {
$storetime. = "0". $now ["Minutes"];
} else {
$storetime. = $now ["Minutes"];
}
$storetime. = ":";
if ($now ["seconds"] <10) {
$storetime. = "0". $now ["seconds"];
} else {
$storetime. = $now ["Seconds"];
}
if (Isset ($data)) {
$counter =++ $data [l];
Setcookie ("data[0]", $storetime, Time () + (60*60*24));
Setcookie ("data[l]", $counter, Time () + (60*60*24)); Setcookie ("data[2]", $username, Time () + (60*60*24));
echo "<b><center>hi". $data [2]. "!!</center></b><br>n";
echo "<b><center>last Login Time:". $data [0]. " </center></b><br>n ";
echo "<b><center>current Date:". $storetime. " </center></b><br>n ";
echo "<b><center>page View Count:". $data [L]. "</center></b><br>n";
echo "<b><center>you have successfully logged in!</center></b>";
Echo ("<b><contor>you can access this area without entering a password for" next HOURS!</CENTER>&L T;/b> ");
} else {
if (Isset ($username) && isset ($password)) {
if ($password = = "SuperPass") {
$counter = 0;
Setcookie ("data[0]", $storetime, Time () + (60*60*24));
Setcookie ("data[l]", $counter, Time () + (60*60*24));
Setcookie ("data[2]", $username, Time () + (60*60*24));
$url = "Location:cookieimp.php";
Header ($url);
}else{
echo "}
}
}
?>