php用户认证及管理(完全版)
时间:2007-02-17 来源:PHP爱好者
用户认证及管理(完全版)
China It Power . ComdcIyofWKzEa7weldWnvagbul3
作者:MAX
China It Power . ComdcIyofWKzEa7weldWnvagbul3
来源:奥索网
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- begin auth.inc --
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<?php
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$id = "xxxCOM";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if(!isset($PHP_AUTH_USER)) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Header("WWW-Authenticate: Basic realm="$id"");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Header("HTTP/1.0 401 Unauthorized");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
require('error.inc');
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$name = $PHP_AUTH_USER;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$pass = $PHP_AUTH_PW;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
require("connect.inc");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$query = "select * from auth where username='$name' && realm='$id'";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$result = mysql_db_query("admin", $query);
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if(mysql_num_rows($result) == 0) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Header("WWW-Authenticate: Basic realm="$id"");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Header("HTTP/1.0 401 Unauthorized");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
require('error.inc');
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$active = mysql_result($result,0,"active");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if($active == 'no') {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
?>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<HTML><HEAD>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<TITLE>404 Not Found</TITLE>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
</HEAD><BODY>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<H1>Not Found</H1>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
The requested URL
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<? echo $REQUEST_URI; ?>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
was not found on this server.<P>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
</BODY></HTML>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<?php
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
?>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- end auth.inc --
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- begin connect.inc --
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<?php mysql_connect("localhost", "user", ""); ?>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- end connect.inc --
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- begin error.inc --
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
此文件存放错误信息及返回!
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- end error.inc --
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- 用户库结构(自己调整)--
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
CREATE TABLE auth (
China It Power . ComdcIyofWKzEa7weldWnvagbul3
id smallint(6) DEFAULT '0' NOT NULL auto_increment,
China It Power . ComdcIyofWKzEa7weldWnvagbul3
username varchar(16) DEFAULT '' NOT NULL,
China It Power . ComdcIyofWKzEa7weldWnvagbul3
lastname tinyblob,
China It Power . ComdcIyofWKzEa7weldWnvagbul3
firstname tinyblob,
China It Power . ComdcIyofWKzEa7weldWnvagbul3
password varchar(16),
China It Power . ComdcIyofWKzEa7weldWnvagbul3
realm varchar(16),
China It Power . ComdcIyofWKzEa7weldWnvagbul3
active char(3),
China It Power . ComdcIyofWKzEa7weldWnvagbul3
PRIMARY KEY (id),
China It Power . ComdcIyofWKzEa7weldWnvagbul3
UNIQUE id (id),
China It Power . ComdcIyofWKzEa7weldWnvagbul3
UNIQUE username (username)
China It Power . ComdcIyofWKzEa7weldWnvagbul3
);
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- 用户库结构结束--
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- 添加用户示例--
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
insert into auth (username, lastname, firstname, password, realm, active) values
China It Power . ComdcIyofWKzEa7weldWnvagbul3
('admin','my','love','password','xxxCOM','yes');
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- 结束--
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
--用户管理程序开始 usermanage.php --
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<?php include("auth.inc"); ?>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<?php
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($PHP_AUTH_USER != "admin") {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Header("WWW-Authenticate: Basic realm="xxxCOM 客户认证"");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Header("HTTP/1.0 401 Unauthorized");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "Access Denied!n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
};
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($PHP_AUTH_PW != "mypassword") {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Header("WWW-Authenticate: Basic realm="xxxCOM 客户认证"");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Header("HTTP/1.0 401 Unauthorized");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "Access Denied!n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
};
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($activate) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
include("connect.inc");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$query1 = "UPDATE auth SET active='yes' where id='$id'";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$result1 = mysql_db_query("admin", $query1);
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($result1) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<font size="+1">n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "$user activatedn";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "
China It Power . ComdcIyofWKzEa7weldWnvagbul3
n<a href="$PHP_SELF">返回</a>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</font>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
} else {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<font size="+1">n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "Error: Unknown Errorn";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "
China It Power . ComdcIyofWKzEa7weldWnvagbul3
n<a href="$PHP_SELF">返回</a>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</font>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($deactivate) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
include("connect.inc");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$query2 = "UPDATE auth SET active='no' where id='$id'";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$result2 = mysql_db_query("admin", $query2);
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($result2) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<font size="+1">n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "$user deactivatedn";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "
China It Power . ComdcIyofWKzEa7weldWnvagbul3
n<a href="$PHP_SELF">返回</a>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</font>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
} else {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<font size="+1">n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "Error: Unknown Errorn";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "
China It Power . ComdcIyofWKzEa7weldWnvagbul3
n<a href="$PHP_SELF">返回</a>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</font>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($delete) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
include("connect.inc");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$query3 = "delete from auth where id='$id'";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$result3 = mysql_db_query("admin", $query3);
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($result3) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<font size="+1">n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "$user 已删除!n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "
China It Power . ComdcIyofWKzEa7weldWnvagbul3
n<a href="$PHP_SELF">返回</a>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</font>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
} else {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<font size="+1">n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "Error: Unknown Errorn";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "
China It Power . ComdcIyofWKzEa7weldWnvagbul3
n<a href="$PHP_SELF">返回</a>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</font>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<html>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<head>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<title>用户管理</title>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</head>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<body>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<form method="post" action="$PHP_SELF">n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<table border="1">n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<tr><th><font size="+1">Username</font></th><th><font size="+1">Real
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Name</font>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
</th><th><font size="+1">Activated</font></th></tr>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
include("connect.inc");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$query = "SELECT * FROM auth";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$result = mysql_db_query("admin", $query);
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($result) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
while ($r = mysql_fetch_array($result)) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$id = $r["id"];
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$username = $r["username"];
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$lastname = $r["lastname"];
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$firstname = $r["firstname"];
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$activated = $r["active"];
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($activated == "yes") {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<tr><td><font size="+1">$username</font></td><td><font size="+1">$lastname,
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$firstname</font>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
</td><td><font size="+1">$activated</font></td><td>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<a href="$PHP_SELF?deactivate=yes&id=$id&user=$username">Deactivate</a>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
</td><td><a href="$PHP_SELF?delete=yes&id=$id">Delete</a></td></tr>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
} elseif ($activated == "no") {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<tr><td><font size="+1">$username</font></td><td><font size="+1">$lastname,
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$firstname
China It Power . ComdcIyofWKzEa7weldWnvagbul3
</font></td><td><font size="+1">$activated</font></td><td><a
China It Power . ComdcIyofWKzEa7weldWnvagbul3
href="$PHP_SELF?activate=yes&id=$id">Activate</a>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
</td><td><a href="$PHP_SELF?delete=yes&id=$id">Delete</a></td></tr>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
mysql_free_result($result);
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</table>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</body>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</html>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
?>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- usermanage.php 结束--
China It Power . ComdcIyofWKzEa7weldWnvagbul3
php爱好者站 http://www.phpfans.net php动态|php基础|php进阶|php模板.
China It Power . ComdcIyofWKzEa7weldWnvagbul3
作者:MAX
China It Power . ComdcIyofWKzEa7weldWnvagbul3
来源:奥索网
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- begin auth.inc --
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<?php
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$id = "xxxCOM";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if(!isset($PHP_AUTH_USER)) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Header("WWW-Authenticate: Basic realm="$id"");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Header("HTTP/1.0 401 Unauthorized");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
require('error.inc');
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$name = $PHP_AUTH_USER;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$pass = $PHP_AUTH_PW;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
require("connect.inc");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$query = "select * from auth where username='$name' && realm='$id'";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$result = mysql_db_query("admin", $query);
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if(mysql_num_rows($result) == 0) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Header("WWW-Authenticate: Basic realm="$id"");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Header("HTTP/1.0 401 Unauthorized");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
require('error.inc');
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$active = mysql_result($result,0,"active");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if($active == 'no') {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
?>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<HTML><HEAD>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<TITLE>404 Not Found</TITLE>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
</HEAD><BODY>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<H1>Not Found</H1>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
The requested URL
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<? echo $REQUEST_URI; ?>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
was not found on this server.<P>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
</BODY></HTML>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<?php
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
?>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- end auth.inc --
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- begin connect.inc --
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<?php mysql_connect("localhost", "user", ""); ?>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- end connect.inc --
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- begin error.inc --
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
此文件存放错误信息及返回!
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- end error.inc --
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- 用户库结构(自己调整)--
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
CREATE TABLE auth (
China It Power . ComdcIyofWKzEa7weldWnvagbul3
id smallint(6) DEFAULT '0' NOT NULL auto_increment,
China It Power . ComdcIyofWKzEa7weldWnvagbul3
username varchar(16) DEFAULT '' NOT NULL,
China It Power . ComdcIyofWKzEa7weldWnvagbul3
lastname tinyblob,
China It Power . ComdcIyofWKzEa7weldWnvagbul3
firstname tinyblob,
China It Power . ComdcIyofWKzEa7weldWnvagbul3
password varchar(16),
China It Power . ComdcIyofWKzEa7weldWnvagbul3
realm varchar(16),
China It Power . ComdcIyofWKzEa7weldWnvagbul3
active char(3),
China It Power . ComdcIyofWKzEa7weldWnvagbul3
PRIMARY KEY (id),
China It Power . ComdcIyofWKzEa7weldWnvagbul3
UNIQUE id (id),
China It Power . ComdcIyofWKzEa7weldWnvagbul3
UNIQUE username (username)
China It Power . ComdcIyofWKzEa7weldWnvagbul3
);
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- 用户库结构结束--
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- 添加用户示例--
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
insert into auth (username, lastname, firstname, password, realm, active) values
China It Power . ComdcIyofWKzEa7weldWnvagbul3
('admin','my','love','password','xxxCOM','yes');
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- 结束--
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
--用户管理程序开始 usermanage.php --
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<?php include("auth.inc"); ?>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<?php
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($PHP_AUTH_USER != "admin") {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Header("WWW-Authenticate: Basic realm="xxxCOM 客户认证"");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Header("HTTP/1.0 401 Unauthorized");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "Access Denied!n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
};
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($PHP_AUTH_PW != "mypassword") {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Header("WWW-Authenticate: Basic realm="xxxCOM 客户认证"");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Header("HTTP/1.0 401 Unauthorized");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "Access Denied!n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
};
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($activate) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
include("connect.inc");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$query1 = "UPDATE auth SET active='yes' where id='$id'";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$result1 = mysql_db_query("admin", $query1);
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($result1) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<font size="+1">n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "$user activatedn";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "
China It Power . ComdcIyofWKzEa7weldWnvagbul3
n<a href="$PHP_SELF">返回</a>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</font>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
} else {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<font size="+1">n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "Error: Unknown Errorn";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "
China It Power . ComdcIyofWKzEa7weldWnvagbul3
n<a href="$PHP_SELF">返回</a>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</font>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($deactivate) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
include("connect.inc");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$query2 = "UPDATE auth SET active='no' where id='$id'";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$result2 = mysql_db_query("admin", $query2);
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($result2) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<font size="+1">n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "$user deactivatedn";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "
China It Power . ComdcIyofWKzEa7weldWnvagbul3
n<a href="$PHP_SELF">返回</a>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</font>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
} else {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<font size="+1">n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "Error: Unknown Errorn";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "
China It Power . ComdcIyofWKzEa7weldWnvagbul3
n<a href="$PHP_SELF">返回</a>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</font>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($delete) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
include("connect.inc");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$query3 = "delete from auth where id='$id'";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$result3 = mysql_db_query("admin", $query3);
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($result3) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<font size="+1">n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "$user 已删除!n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "
China It Power . ComdcIyofWKzEa7weldWnvagbul3
n<a href="$PHP_SELF">返回</a>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</font>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
} else {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<font size="+1">n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "Error: Unknown Errorn";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "
China It Power . ComdcIyofWKzEa7weldWnvagbul3
n<a href="$PHP_SELF">返回</a>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</font>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
exit;
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<html>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<head>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<title>用户管理</title>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</head>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<body>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<form method="post" action="$PHP_SELF">n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<table border="1">n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<tr><th><font size="+1">Username</font></th><th><font size="+1">Real
China It Power . ComdcIyofWKzEa7weldWnvagbul3
Name</font>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
</th><th><font size="+1">Activated</font></th></tr>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
include("connect.inc");
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$query = "SELECT * FROM auth";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$result = mysql_db_query("admin", $query);
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($result) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
while ($r = mysql_fetch_array($result)) {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$id = $r["id"];
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$username = $r["username"];
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$lastname = $r["lastname"];
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$firstname = $r["firstname"];
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$activated = $r["active"];
China It Power . ComdcIyofWKzEa7weldWnvagbul3
if ($activated == "yes") {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<tr><td><font size="+1">$username</font></td><td><font size="+1">$lastname,
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$firstname</font>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
</td><td><font size="+1">$activated</font></td><td>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
<a href="$PHP_SELF?deactivate=yes&id=$id&user=$username">Deactivate</a>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
</td><td><a href="$PHP_SELF?delete=yes&id=$id">Delete</a></td></tr>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
} elseif ($activated == "no") {
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "<tr><td><font size="+1">$username</font></td><td><font size="+1">$lastname,
China It Power . ComdcIyofWKzEa7weldWnvagbul3
$firstname
China It Power . ComdcIyofWKzEa7weldWnvagbul3
</font></td><td><font size="+1">$activated</font></td><td><a
China It Power . ComdcIyofWKzEa7weldWnvagbul3
href="$PHP_SELF?activate=yes&id=$id">Activate</a>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
</td><td><a href="$PHP_SELF?delete=yes&id=$id">Delete</a></td></tr>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
}
China It Power . ComdcIyofWKzEa7weldWnvagbul3
mysql_free_result($result);
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</table>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</body>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
echo "</html>n";
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
?>
China It Power . ComdcIyofWKzEa7weldWnvagbul3
China It Power . ComdcIyofWKzEa7weldWnvagbul3
-- usermanage.php 结束--
China It Power . ComdcIyofWKzEa7weldWnvagbul3
php爱好者站 http://www.phpfans.net php动态|php基础|php进阶|php模板.
相关阅读 更多 +