第一个页面:cookie.html
//一个简单的页表的登录的界面
<!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=UTF-8">
<title>denglu jiemian </title>
</head>
<body>
<form action="cookie.php" method="post">
<table>
<tr>
<td>name</td>
<td>
<input type="text" name="name">
</td>
</tr>
<tr>
<td>password</td>
<td>
<input type="text" name="password">
</td>
</tr>
<tr>
<td>
<input type="submit" value="提交">
</td>
<td>
<input type="reset" value="重置">
</td>
</tr>
</table>
</form>
</body>
</html>第二个页面:cookie.php<?php
$name=$_POST['name']; //从表单中获取相应 的名字值
$password2=$_POST['password']; //从表单中获取相应的密码
if(!isset($_COOKIE['username']) && !isset($_COOKIE['password2'])) //检查是否设置了cookie
{
echo "the first time for visit";
setcookie("username","$name",time()+20); //没有设置cookie,设置username的cookie
setcookie("password2","$password",time()+20); //设置password的cookie
}
else
{
echo "welcome next visited";
}
?>
<a href="cookie_chuli.php">next</a>第三个页面:
<?php
echo "chuli cookie"."<br>";
$name2=$_COOKIE['username'];
$password3=$_COOKIE['password2']; //获取cookie的相关值的语句的写法
echo "$name2"."<br>"."$password3";
// header("Location:cookie4.php");
?>
<a href="cookie4.php">next </a>第四个页面:
<?php
echo "退出界面";
setcookie("username"," ",time()-30); //删除相应的cookie的值,使用的函数。功能,使得username变为空,时间设置为负值即可
//header("Location:cookie5.html"); //感觉还是用超链接比较好,这个header函数跳的太快了
?>
<a href=cookie.html>next</a>