php cookie 操作

 

创建 cookie
<?php 
setcookie("user", "Alex Porter", time()+3600);
?>



取回 Cookie 的值
<?php
// Print a cookie
echo $_COOKIE["user"];
// A way to view all cookies
print_r($_COOKIE);
?>



isset() 函数来确认是否已设置了 cookie
<html>
<body>
<?php
if (isset($_COOKIE["user"]))
  echo "Welcome " . $_COOKIE["user"] . "!<br />";
else
  echo "Welcome guest!<br />";
?>
</body>
</html>




删除 cookie
<?php 
// set the expiration date to one hour ago
setcookie("user", "", time()-3600);
?>

 

posted @ 2019-07-16 21:11  anobscureretreat  阅读(208)  评论(0编辑  收藏  举报