会员管理系统练习

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
    include ("conn.php");
    if(isset($_COOKIE['username'])){
        $sql="select * from 'user' where username ='".$_COOKIE['username']."'";
        $rs=mysql_fetch_array(mysql_query($sql));
        $code=md5($rs['username'].$rs['pwd']);
        if (!empty($rs['username'])&&$_COOKIE['code']==$code) {
            echo $rs['username']."欢迎来到登陆首页!<a href='logout.php'>退出登陆</a>";
        }
        else{
            echo "非法操作,<a href='login.php'>请登录</a>";
        }
    }
        else {
        echo"尚未登陆,<a href='login.php'>请登录</a>";    
            
        }
?>
</head>
<body>
</body>
</html>

2.reg.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<?php
include("conn.php");
if(isset($_post['reg'])){
if(!empty($_post['user'])&&!empty($_post['password'])){
$sql="select * from 'user' where 'username'='".$_POST['user']."'";
$query=mysql_query($sql);
$rr=mysql_fetch_array($query);
if($rr[username]!=$_POST['user']){
    $sql="INSERT INTO 'user'('id','username','pwd','email')VALUES(NULL,'".$_POST['user']."','".md5($_POST['password'])."','".$_POST['email']."'));";
    if($state){
        setcookie("username",$_POST['user']);
        setcookie("code",md5($_POST['user'].md5($_POST['password'])));
        echo"<script>alert('注册成功!');window.location.href='index.php'</script>";
    }
}
else{
    echo"用户名已存在";
}

}
else{
    echo"用户名和密码不能为空";    
}
}
?>
</head>

<body>
<a href='index.php'>返回首页</a>&nbsp;&nbsp;&nbsp;<a href='login.php'>登陆</a>
<form>
用户名:<input type="text" name="user"/><br/>
密码:    <input type="password" name="password"/><br/>
E-MAIL:<input type="text" name="email"/><br/>
<input type="submit" name="reg" value="提交" />

</form>
</body>
</html>


3.login.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>

<?php
include("conn.php");
if(isset($_POST['submit'])){
if(empty($_POST["username"])){
echo"<script>alert('用户名不能为空');</script>";        
}else if(empty($_POST["password"])){
echo"<script>alert('密码不你能为空');</script>";
}else{
$sql="select * from 'user' where 'username'='".$_POST['username']."'limit 1";

$query=mysql_query($sql);
$rs=mysql_fetch_array($query);
if(!empty($rs['username'])){
if(($rs['pwd'])==md5($_POST['password'])){
setcookie("username",$rs['username']);
setcookie("code",md5($rs['username'].md5($rs['pwd'])));
echo"<script>alert('登录成功');window.location.href='index.php'</script>";
}else{
echo"<script> alert('密码错误');</script>";
}
}else{
echo"<script>alert('用户名不存在');</script>";                                
}                
}
}
?>
</head>
<body>
<a href='index.php'>返回首页</a>&nbsp;&nbsp;&nbsp;<a href='reg.php'>注册</a>
<form action=" " method="post">
用户名:<input type="text" name="username"/><br/>
密&nbsp;&nbsp;&nbsp;码:
<input type="password" name="password"/><br/>
<input type="submit" name="submit" value="登录"/>
</form>
</body>
</html>

4.loginout.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
    setcookie('username',"",time()-1);
    setcookie('code',"",time()-1);
    echo"<script>alert('退出成功');window.localtion.href='index.php'</script>";
?>

5.conn.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<?php
    mysql_connect("localhost","root","root")or die(mysql_error());
    mysql_select_db("user")or die(mysql_error());
    mysql_query("set names 'utf8'");
   // echo"数据库连接成功";

?>

</body>
</html>


练习一下cookie的使用。。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值