码迷,mamicode.com
首页 > 其他好文 > 详细

cookie使用案例

时间:2020-08-06 13:09:12      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:bsp   date   BMI   name   isset   text   reset   cti   tco   

index.php

<html>
<body>
<h1>Login In</h1>
<?php
$user=isset($_COOKIE[‘id‘])?$_COOKIE[‘id‘]:‘‘;
$pwd=isset($_COOKIE[‘password‘])?$_COOKIE[‘password‘]:‘‘;
?>
<form method = "post" action="./base.php">
<table>
<tr>
<td>User id</td>
<td> <input type="text" name="id" value="<?php echo $user;?>"></td>
</tr>
<tr>
<td>Password</td>
<td ><input type="password" name="password" value="<?php echo $pwd;?>"></td>
</tr>
<tr>
<td><input type="submit" value="login"></td>
<td><input type="reset" value="reset"></td>
</tr>
</table>
</form>
</body>
</html>

base.php 


<?php
$user=$_POST["id"];
$pwd=$_POST["password"];
if(!empty($_COOKIE[‘id‘])){
setcookie("id",$user,time()+3600);
}else{
setcookie("id",$user,time()+3600);
}
if(!empty($_COOKIE[‘password‘])){
setcookie("password",$user,time()+3600);
}else{
setcookie("password",$user,time()+3600);
}
echo "welcome, ".$_POST["id"]."login success!";
echo "<br/><a href=‘index.php‘>Baack to login</a>";
if(!empty($_COOKIE[‘lastVisit‘])){
echo "your last login time : ".$_COOKIE[‘lastVisit‘];
setcookie("lastVisit",date("Y-m-d H:i:s"),time()+24*3600*30);
}else{
echo "your first login time :";
setcookie("lastVisit",date("Y-m-d H:i:s"),time()+24*3600*30);
}
?>

cookie使用案例

标签:bsp   date   BMI   name   isset   text   reset   cti   tco   

原文地址:https://www.cnblogs.com/hai-/p/13445310.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!