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);
?>

原文地址:https://www.cnblogs.com/sea-stream/p/11197521.html