分别制作一个PHP格式的个人主页和登录页
用户名为,若登录成功,则利用cookie变量保存登录信息,保存时间为一天、一周、一月和一年,然后跳转到个人主页。若登录失败,则跳转到登录面面。不链接数据库怎么实现啊?
简单示例如下
login.php
<meta charset="utf-8"/>
<?php
$un=isset($_POST["un"])?$_POST["un"]:false;
//$type 1:一天 2:一周 3:一个月 4:1年
function setCookieValue($un,$type){
$sec=3600*24;
if($type==2)$sec*=7;
else if($type==3)$sec*=30;
else if($type==4)$sec*=365;
setcookie('un',$un,time()+$sec);
}
if($un!==false&&$un=="test"){
setCookieValue($un,1);//
header("location:index.php");
}
?>
<title>登录系统</title>
<h1>登录系统</h1>
<form method="POST">
用户名:<input type="text" name="un"/><input type="submit" value="登录">
</form>
index.php
<?php
$un=isset($_COOKIE["un"])?$_COOKIE["un"]:false;
if($un===false){//cooki不存在跳转到登录页面
header("location:login.php");
die("");
}
?>
<meta charset="utf-8"/>
<title>个人主页</title>
<h1><?php echo $un; ?>的个人主页</h1>
看我的专栏。即可实现