数据库规划:
在mysql中:
代码
create database example;
use example;
create table member(
serial int unsigned not null primary key auto_increment,
id varchar(30) unique key not null,passwd varchar(20) not null,
status int unsigned not null,
rank int unsigned not null);
insert into member values('','adm','adm123456',1,100);
程序编写:
1.公共程序:
(1)数据库连接:sql_connect.php:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?php
/* Connectint,selecting database */
$link=mysql_connect('localhost','root','lizhaoyi')
or die("Could not connect:".mysql_error());
//echo "Connected successfully";
mysql_select_db("example") or die("Could not select database");
?>
(2) 网页重导向:my_msg.php:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?php
Function my_header($redirect){
echo "<script language=\"javascript\">";
echo "location.href='".$redirect."'";
echo "</script>";
return;
}
Function my_msg($msg,$redirect){
echo "<SCRIPT Language=javascript>";
echo "window.alert('".$msg."')";
echo "</SCRIPT>";
echo "<script language=\"javascript\">";
echo "location.href='".$redirect."'";
echo "</script>";
return;
}
?>
2.会员注册模块:
(1).add.html(用于提供会员注册表单):
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>会员注册检查</title>
</head>
<body bgcolor="white" text="black" link="blue" vlink="purple"
alink="red">
<h1 align="center">会员注册</h1>
<form name="form1" action=add_chk.php method=post>
<p align="center">请输入你要使用的账号:<input type="text" name="id"></input></p>
<p align="center">请输入你要使用的密码:<input type="password" name="passwd"></input></p>
<p align="center">请重复输入你的密码以确认:<input type="password"
name="repasswd"></input></p>
<p align="center"><input type="submit" name="提交"><input
type="reset" name="重设"></input></p>
</form>
</body>
</html>
程序运行输出:
(2).add_chk.php(用于检查会员输入数据并添加数据库数据):
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?php
include_once("sql_connect.php");
include_once("my_msg.php");
?>
<?php
//检查数据
if($_POST['id']=='' or $_POST['passwd']=='' or $_POST['repasswd']==''){
my_msg("字段不可空白","add.html");
}
if($_POST['passwd']!=$_POST['repasswd']){
my_msg("密码并不相符,需要重复输入相同密码以确认","add.html");
}
$sqlstr="insert into member values(null,'".$_POST['id']."','".$_POST['passwd']."',1,1)";
//组合sql
$result=mysql_query($sqlstr,$link);
//执行sql
//跳至窗口页
my_msg("添加用户成功,请以此用户账号/密码重新登录","login.html");
mysql_free_result($result);
mysql_close($link);
?>
程序运行输出:
3.会员登录模块:
(1).login.html(用于提供登录表单):
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用户登录</title>
</head>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<h1 align="center">用户登录</h1>
<form name="form1" action=login_chk.php method=post>
<p align="center">登录用户:<input type="text" name="id"></input></p>
<p align="center">用户密码:<input type="password" name="passwd"></input></p>
<p align="center"><input type="submit" name="登录" value="登录" ><input type="reset" name="取消" value="取消"></input>
</form>
<h3 align="center"><a href=add.html>注册</a></h3>
</body>
</html>
程序运行输出:
(2).login_chk.php:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?php
include_once("sql_connect.php");
include_once("my_msg.php");
?>
<?php
//检查数据
if($_POST['id']=='' or $_POST['passwd']==''){
my_msg("字段不可空白","login.html");
}
$sqlstr="select * from member where id='".$_POST['id']."' and passwd='".$_POST['passwd']."' and status=1";
$result=mysql_query($sqlstr,$link);
$row=mysql_fetch_array($result,MYSQL_BOTH);
if(mysql_num_rows ($result)==1 && $row["rank"]==100){
setcookie("cookie_chk","adm_logined");
setcookie("cookie_id",$_POST['id']);
my_header("adm.php");//管理员登录
}elseif(mysql_num_rows ($result)==1 && $row["rank"]==1){
setcookie("cookie_chk","logined");
setcookie("cookie_id",$_POST['id']);
my_header("main.php");//会员 登录
}else{
my_msg("登录失败,请重新登录","login.html");
}
mysql_free_result($result);
mysql_close($link);
?>
程序运行输出:
(3).main.php(会员主功能表):
1 <?php
2 include_once("sql_connect.php");
3 include_once("my_msg.php");
4 ?>
5 <html>
6 <head>
7 <meta http-equiv="content-type" content="text/html;charset=gb2312"></meta>
8 <title>会员主功能表</title>
9 </head>
10 <body bgcolor="white" text="black" link="blue" vlink="purple"
11 alink="red">
12 <?php
13 if(isset($_COOKIE['cookie_chk'])){
14 if($_COOKIE['cookie-chk']!="login.html");
15 }
16 ?>
17 <h1 align="center">欢迎
18 <?echo $_COOKIE['cookie_id'];
19 ?>
20 进入会员区<br>会员主功能表</h1>
21 <h3 align="center"><a href=mod.html>更改密码</a></h3>
22 <h3 align="center"><a href=login.html>重新登录</a></h3>
23 </body>
24 </html>
程序运行输出:
3.会员修改数据模块:
(1).mod.html(r提供密码修改界面):
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-Type" content="text/html; charset=gb2312">
<title>会员更改密码</title>
</head>
<body bgcolor="white" text="black" link="blue" vlink="purple"
alink="red">
<h1 align="center">会员更改密码</h1>
<form name="form1" action=mod_chk.php method=post>
<p align="center">新密码:<input type="password" name="passwd"></input></p>
<p align="center">确认密码:<input type="password" name="repasswd"></input></p>
<p align="center"><input type="submit" name=“提交"><input type="reset" name="重设"></input></p>
</form>
<h3 align="center"><a href=main.php>回到主菜单</a></h3>
</body>
</html>
程序运行输出:
(2).mod_chk.php(检查会员输入资料并更改密码):
mod_chk.php密码更改检查
程序运行输出:
4.管理员删除会员模块:
(1).adm.php(管理员专区):
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?php
2 include_once("sql_connect.php");
3 include_once("my_msg.php");
4 ?>
5 <html>
6 <head>
7 <meta http-equiv="content-type" content="text/html;charset=gb2312"></meta>
8 <title>管理员主功能表</title>
9 </head>
10 <body bgcolor="white" text="black" link="blue" vlink="purple"
11 alink="red">
12 <?php
13 if (isset($_COOKIE['cookie_chk'])){
14 if($_COOKIE['cookie_chk']!="adm_logined"){
15 my_msg("登录失败,请重新登录","login.html");
16 }
17 }else{
18 my_msg("登录失败,请重新登录","login.html");
19 }
20 ?>
21 <h1 align="center">欢迎<?php echo $_COOKIE['cookie_id'];?>进入管理员专区
22 <br>
23 管理员主功能表
24 </h1>
25 <h3 align="center"><a href=del.php>删除会员</a></h3>
26 <h3 align="center"><a href=mod_passwd.php>更改会员密码</a></h3>
27 <h3 align="center"><a href=login.html>重新登录</a></h3>
28 </body>
29 </html>
程序运行输出:管理员登录
(2).del.php(管理员删除会员账号菜单):
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?php
2 include_once("sql_connect.php");
3 include_once("my_msg.php");
4 ?>
5 <html><head>
6 <meta http-equiv="content-type" content="text/html; charset=gb2312">
7 <title>管理员删除会员</title>
8 </head>
9 <body bgcolor="white" text="black" link="blue" vlink="purple"
10 alink="red">
11 <?php
12 if (isset($_COOKIE['cookie_chk'])){
13 if($_COOKIE['cookie_chk']!="adm_logined"){
14 my_msg("登录失败,请重新登录","login.html");
15 }
16 }else{
17 my_msg("登录失败,请重新登录","login.html");}
18 $sqlstr="select id from member where rank=1 and status=1";
19 $result=mysql_query($sqlstr,$link);
20 ?>
21 <h1 align="center">选择要删除的会员 </h1><p align="center"></p><center>
22 <form name="form1" action=del_chk.php method=post>
23 <SELECT name="del_id" size="1">
24 <?php while($row=mysql_fetch_array($result,MYSQL_BOTH)){
25 echo "<OPTION>".$row["id"];}
26 ?> </SELECT>
27 <input type="submit" name="提交"><input type="reset" name="重设">
28 </form>
29 <h3 align="center"><a href=adm.php>回到主菜单</a></h3>
30 <h3 align="center"><a href=login.html>重新登录</a></h3>
31 </center>
32 </html>
33
程序运行输出:
(3).del_chk.php(管理员删除会员账号检查):
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?php
2 include_once("sql_connect.php");
3 include_once("my_msg.php");
4 ?>
5 <?php
6 //检查数据
7
8 if($_POST['del_id']==''){
9 my_msg("字段不可空白","del.php");
10 }
11
12 $sqlstr="update member set status=0 where id ='".$_POST['del_id']."'";
13 //组合sql
14 $result=mysql_query($sqlstr,$link);
15 //执行sql
16
17 //跳至窗口页
18 my_msg("删除用户成功,回到主菜单","adm.php");
19
20 mysql_free_result($result);
21 mysql_close($link);
22 ?>
23
程序运行输出:
5.管理员修改会员数据模块:
(1).mod_passwd.php(提供会员菜单并可输入新密码):
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?php
2 include_once("sql_connect.php");
3 include_once("my_msg.php");
4 ?>
5 <html><head>
6 <meta http-equiv="content-type" content="text/html; charset=gb2312"></meta>
7 <title>管理员更改会员 密码</title>
8 </head>
9 <body bgcolor="white" text="black" link="blue" vlink="purple"
10 alink="red">
11 <?php if(isset($_COOKIE['cookie_chk'])) {
12 if($_COOKIE['cookie_chk']!="adm_logined"){
13 my_msg("登录失败,请重新登录","login.html");
14 }
15 }else{
16 my_msg("登录失败,请重新登录","login.html");
17 }
18 $sqlstr="select id from member where rank=1 and status=1";
19 $result=mysql_query($sqlstr,$link);
20 ?>
21 <h1 align="center">选择要更改密码的会员</h1><center>
22 <form name="form1" action=mod_passwd_chk.php method=post>
23 <SELECT name="mod_id" size="1">
24 <?php while($row=mysql_fetch_array($result,MYSQL_BOTH)){
25 echo "<OPTION>".$row["id"];
26 }
27 ?>
28 </SELECT>
29 请输入这个会员的新密码:<input type="password" name="passwd"><br></br>
30 请重复输入这个会员的新密码以确认:<input type="password" name="repasswd"></input><br></br>
31 <input type="submit" name="提交"><input type="reset" name="重设"></input><br></br>
32 </form><br><br></br>
33 <h3 align="center"><a href=adm.php>回到主菜单</a></h3>
34 <h3 align="center"><a href=login.html>重新登录</a></h3>
35 </center>
36 </html>
程序运行输出:
(2).mod_passwd_chk.php(确认更改会员密码):
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?php
2 include_once("sql_connect.php");
3 include_once("my_msg.php");
4 ?>
5 <?php
6 //检查数据
7
8 if($_POST['passwd']=='' or $_POST['repasswd']==''){
9 my_msg("字段不可空白","mod_passwd.php");
10 }
11 if($_POST['passwd']!=$_POST['repasswd']){
12 my_msg("密码并不相符,需重复输入相同密码以确认","mod_passwd.php");
13 }
14
15 $sqlstr="update member set passwd='".$_POST['passwd']."'where id ='".$_POST['mod_id']."'";
16 $result=mysql_query($sqlstr,$link);
17 //执行sql
18
19 //跳至窗口页
20 my_msg("更改密码成功,回到主菜单","adm.php");
21
22
23 mysql_free_result($result);
24 mysql_close($link);
25 ?>
26 <h3 align="center"><a href=adm.php>回到主菜单</a></h3>
27 <h3 align="center"><a href=login.html>重新登录</a></h3>
程序运行输出: