寫入cookie
代碼如下 復制代碼setcookie(name, value, expire, path, domain);
function w_cookie($n, $c, $e = 0,$isdes=1)
{
if($isdes==1){$c=endes($c,deskey);}
$exp = time() + 3600 * 24 * 30;
if($e == 0)
{
setcookie($n, $c, $exp,"/");
}
else
{
setcookie($n, $c,0,"/");
}
}
關閉cookie方法就是把它設置過期即可。
例1
寫cookie
代碼如下 復制代碼function cookie($var, $value='', $time=0, $path='', $domain=''){
$_COOKIE[$var] = $value;
if(is_array($value)){
foreach($value as $k=>$v){
setcookie($var.'['.$k.']', $v, $time, $path, $domain, $s);
}
}else{
setcookie($var, $value, $time, $path, $domain, $s);
}
}
//調用方法
cookie("website","安卓主題","./","www.111cn.net");
//
例2
防止重復提交
代碼如下 復制代碼$time = time() + 300; //5分鐘過期
$code = md5($string . $time . $salt);
setcookie('check_time', $time);
setcookie('code', $code);
//驗證部分
$TIME = time();
if($check_time < $TIME)//如果服務器時間比驗證時間大,算過期
//expire過期
if(md5($string . $check_time . $salt) !== $code)
更多關於php cookie用法可參考:http://www.111cn.net/tags.php/php%20cookie/