本页文章导读:
▪php实例之基于文件的登录验证 php基于文件的登录验证,代码如下:
<?php
/**
* 基于文件的登录
* edit by www.
*/
$authorized = FALSE;
if (isset($_SERVER['PHP_AUTH_USER']) &&
isset($_SERVER['PHP_AUTH_PW'])) {
$authFile = file(".........
▪php实例之基于Cookie的登录表单和获取最后登录时间 1,html部分
<html>
<head>
<title>基于cookie的登录表单,密码提交页-www.</title>
</head>
<body>
<form name="forml" method="POST"
action="/blog_article/CookieBasedPasswordLogin.html">
<.........
▪php实例之浏览器中显示密码提示框 1,php代码
<?php
/**
* 浏览器 显示密码提示框
* edit by www.
*/
if (($_SERVER['PHP_AUTH_USER'] != 'specialuser') ||
($_SERVER['PHP_AUTH_PW'] != 'secretpassword')) {
header('WWW-Authenticate: Basic Realm="Secret
.........
[1]php实例之基于文件的登录验证
来源: 互联网 发布时间: 2013-12-24
php基于文件的登录验证,代码如下:
<?php
/**
* 基于文件的登录
* edit by www.
*/
$authorized = FALSE;
if (isset($_SERVER['PHP_AUTH_USER']) &&
isset($_SERVER['PHP_AUTH_PW'])) {
$authFile = file("./password.txt"); // 密码文件
foreach ($authFile as $login) {
list($username, $password) = explode(":", $login);
$password = trim($password);
if (($username == $_SERVER['PHP_AUTH_USER']) &&
($password == md5($_SERVER['PHP_AUTH_PW']))) {
$authorized = TRUE;
break;
}
}
}
// 验证失败则显示提示框或401错误
if (! $authorized) {
header('WWW-Authenticate: Basic Realm="Secret
Stash"');
header('HTTP/1.0 401 Unauthorized');
print('您必须提供正确的凭证!');
exit;
}
?>
<!-- password.txt
joe:60d99e58d66a5e0f4f89ec3ddd1d9a80
-->
[2]php实例之基于Cookie的登录表单和获取最后登录时间
来源: 互联网 发布时间: 2013-12-24
1,html部分
<html>
<head>
<title>基于cookie的登录表单,密码提交页-www.</title>
</head>
<body>
<form name="forml" method="POST"
action="/blog_article/CookieBasedPasswordLogin.html">
<table>
<tr>
<td colspan="2" >
<div align="center"><b>请输入您的密码</b></div>
</td>
</tr>
<tr>>
<td>
<div align="right">用户名:</div>
</td>
<td>
<input type="text" name="username">
</td>
</tr>
<tr>
<td>
<div align="right">密 码:</div>
</td>
<td>
<input type="password" name="password">
</td>
</tr>
<tr>
<td colspan="2">
<center>
<input type="submit" name="Submit" value="登 录">
</center>
</td>
</tr>
</table>
</form>
</body>
</html>
2,登录检测页 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>最后登录时间 :" .$data[0] .
"</center></b><br>\n";
echo "<b><center>当前日期 :" .$storetime.
"</center></b><br>\n";
echo "<b><center>网页浏览记录 :" . $data[l].
"</center></b><br>\n";
echo "<b><center>您已经成功登录。</center></b>";
echo ("<b><contor>您可以在接下来的24小时内,无须再提供密码均可访问。</center></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 "<hl><center>密码验证失败!</center></hl>";
}
}
}
?>
-->
[3]php实例之浏览器中显示密码提示框
来源: 互联网 发布时间: 2013-12-24
1,php代码
<?php
/**
* 浏览器 显示密码提示框
* edit by www.
*/
if (($_SERVER['PHP_AUTH_USER'] != 'specialuser') ||
($_SERVER['PHP_AUTH_PW'] != 'secretpassword')) {
header('WWW-Authenticate: Basic Realm="Secret
Stash"');
header('HTTP/1.0 401 Unauthorized');
print('You must provide the proper credentials!');
exit;
}
?>
2,打开浏览器密码对话框和认证用户基于数据库
<?php
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_connect("localhost","authenticator","secret") or
die("连接数据库服务器失败!");
mysql_select_db("gilmorebook") or die("未能连接验证数据库。");
$query = "SELECT username, pswd FROM user WHERE
username='$_SERVER[PHP_AUTH_USER]'
AND pswd=MD5('$_SERVER[PHP_AUTH_PW]')
AND
ipAddress='$_SERVER[REMOTE_ADDR]'";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0)
authenticate_user();
mysql_close();
}
?>最新技术文章: