cookie
1. 用户浏览器支持cookie功能,就可以使用setcookie来客户端新建一个cookie
2.通过HTTP标头发送设置,因此必须在输出内容前setcookie
setcookie($name,$value,$expire,$path,$domain,$secure)
$value 字符串或数值。不能是数组。
$expire time()+数字
$path 服务器端指定路径,当设定此值时,服务器只有在指定路径下的程序可以存取此cookie
$domain 要使cookie能在 feiliu.com 域名下的所有子域名都有效,设为‘.feiliu.com’
$secure 默认为false
setcookie("username","wanghejun",time()+3600); echo $_COOKIE["username"];
如果想要把数组传给cookie
setcookie("user[name]","wanghejun"); setcookie("user[age]",18); foreach($_COOKIE['user'] as $k=>$v){ ... }
删除cookie
setcookie("username",'',time()-1);
session
session_start(); $_SESSION["username"] = "wanghejun"; echo $_SESSION["username"]; /*注销session分三步*/ unset($_SESSION["username"]); if(isset($_COOKIE[session_name()])){ setcookie(session_name(),'',time()-1); } session_destroy();