A cookie is a small file that is sent on the browser side, which can be used to record user-manipulated records, such as access to those files, etc.
Write Cookie
| The code is as follows |
Copy Code |
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, "/"); } } |
The way to turn off cookies is to set it to expire.
Example 1
Write a cookie
| The code is as follows |
Copy Code |
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); } }
Calling methods
Cookies ("website", "Android Theme", "./", "www.hzhuti.com"); // |
Example 2
Prevent duplicate Submissions
| The code is as follows |
Copy Code |
$time = time () + 300; Expires in 5 minutes $code = MD5 ($string. $time. $salt); Setcookie (' Check_time ', $time); Setcookie (' Code ', $code); Validation section $TIME = time (); if ($check _time < $TIME)//If the server time is greater than the validation time, the expiration date Expire expired
if (MD5 ($string. $check _time. $salt)!== $code) |
For more information on PHP cookie usage, refer to: http://www.bKjia.c0m/tags.php/php%20cookie/
http://www.bkjia.com/PHPjc/628924.html www.bkjia.com true http://www.bkjia.com/PHPjc/628924.html techarticle A cookie is a small file that is sent on the browser side, which can be used to record user-manipulated records, such as accessing those files such as the write cookie code below the copy code Setcookie (name, VA ... ).