cookie的应用

在登录的时候,给用户一个记住用户已经登录的功能。就是用户如果一次登录成功,下次再访问就不用再登陆一次了。
如果用户从未登陆过或者已经等处,则提示用户需要登录

<?php
$user=$_POST["user"];
setcookie("user", "$user");
?>
<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
if (isset($_COOKIE["user"]))
{
echo "Welcome " . $_COOKIE["user"];
}
else{
echo '<form action="cookie.php" method="post">';
echo 'user: <input type="text" name="user" />';
echo 'password: <input type="password" name="pwd" /><br />';
echo '<input type="submit" value="login" /><input type="reset" value="reset" />';
echo '</form>';}
?>
</body>
</html>

 

 

posted on 2010-09-18 00:17  lovening  阅读(131)  评论(0编辑  收藏  举报