当前位置: 首页 > 图文教程 > 网络编程 > PHP > PHP用户认证及管理完全源码

PHP
新手入门:学习掌握动态网页PHP的编程语句
PHP建设论坛:Discuz!论坛快速架设指南
理解动态网页技术PHP与数组的应用
PHP初学:实例详细学习PHP的简单语法
PHP实例:PHP生成带有雪花背景的网站验证码
PHP网站开发中关于包含路径问题的解决方案
用PHP实现网页开发中的翻页跳转
用PHP程序实现随机广告图片显示
如何使PHP文件与HTML代码更好的分离
PHP关于代码转换问题比较完善的解决办法
新手如何使用PHP创建RSS阅读器
用PHP程序为自己网站打造一个搜索引擎
PHP实现文件安全下载的程序
快速掌握MySQL数据库中SELECT语句
用javascript+php随机显示图片
论Web 2.0 时代PHP的地位
用动态网页技术PHP打造个人网站全攻略
问题解决:无法载入MYSQL扩展,请检查PHP配置
新手入门:PHP网站开发中常见问题汇总
用PHP程序实现删除目录的三种方法实例

PHP用户认证及管理完全源码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 25 ::
收藏到网摘: n/a

  -- begin auth.inc --  


<?php  


$id = "xxxCOM";  


if(!isset($PHP_AUTH_USER)) {  

Header("WWW-Authenticate: Basic realm="$id"");  

Header("HTTP/1.0 401 Unauthorized");  

require('error.inc');  

exit;  

}  


$name = $PHP_AUTH_USER;  

$pass = $PHP_AUTH_PW;  

require("connect.inc");  

$query = "select * from auth where username='$name' && realm='$id'";  

$result = mysql_db_query("admin", $query);  

if(mysql_num_rows($result) == 0) {  


Header("WWW-Authenticate: Basic realm="$id"");  

Header("HTTP/1.0 401 Unauthorized");  

require('error.inc');  

exit;  

}  


$active = mysql_result($result,0,"active");  

if($active == 'no') {  


?>  

<HTML><HEAD>  

<TITLE>404 Not Found</TITLE>  

</HEAD><BODY>  

<H1>Not Found</H1>  

The requested URL  

<? echo $REQUEST_URI; ?>  

was not found on this server.<P>  

</BODY></HTML>  

<?php  

exit;  

}  

?>  


-- end auth.inc --  


-- begin connect.inc --  


<?php mysql_connect("localhost", "user", ""); ?>  


-- end connect.inc --  


-- begin error.inc --  


此文件存放错误信息及返回!  


-- end error.inc --  


-- 用户库结构(自己调整)--  


CREATE TABLE auth (  

id smallint(6) DEFAULT '0' NOT NULL auto_increment,  

username varchar(16) DEFAULT '' NOT NULL,  

lastname tinyblob,  

firstname tinyblob,  

password varchar(16),  

realm varchar(16),  

active char(3),  

PRIMARY KEY (id),  

UNIQUE id (id),  

UNIQUE username (username)  

);  


-- 用户库结构结束--  


-- 添加用户示例--  


insert into auth (username, lastname, firstname, password, realm, active) values ('admin','my','love','password','xxxCOM','yes');  


-- 结束--  


--用户管理程序开始 usermanage.php --  

<?php include("auth.inc"); ?>  

<?php  


if ($PHP_AUTH_USER != "admin") {  

Header("WWW-Authenticate: Basic realm="xxxCOM 客户认证"");  

Header("HTTP/1.0 401 Unauthorized");  

echo "Access Denied!n";  

exit;  

};  


if ($PHP_AUTH_PW != "mypassword") {  

Header("WWW-Authenticate: Basic realm="xxxCOM 客户认证"");  

Header("HTTP/1.0 401 Unauthorized");  

echo "Access Denied!n";  

exit;  

};  


if ($activate) {  


include("connect.inc");  

$query1 = "UPDATE auth SET active='yes' where id='$id'";  

$result1 = mysql_db_query("admin", $query1);  


if ($result1) {  

echo "<font size="+1">n";  

echo "$user activatedn";&nb