phpcookie注销设置输出和注销学习笔记

114 阅读1分钟
这是一个朋友在学php时的一个学习笔记,其功能就是设置cookie然后注销及输出cookie值的具体操作方法.
setcookie() 函数用于设置 cookie.
注释:setcookie() 函数必须位于 标签之前.
语法
setcookie(name, value, expire, path, domain);
实例代码如下:
  • //注销cookie
  • if(isset($_GET['out'])){
  • setcookie('us',"");
  • echo "《script》location.href='index.php'《script》";
  • }
  • //设置cookie
  • if(isset($_POST['sub'])){
  • setcookie("us",$_POST['user'],time()+3600);
  • echo "《script》location.href='index.php'《script》";
  • }
  • //输出和注销cookie
  • if($_COOKIE['us']){
  • echo $_COOKIE['us'];
  • echo "注销cookies";
  • }
  • ?>
  • <form method="post"</form method=>
  • <input type="text"</input type= name="user">
  • <input type="password"</input type= name="pass">
  • <input type="submit"</input type= name="sub" value="提交">