/*
The Setcookie () function defines a cookie that is sent by the remainder of the HTTP header together. Like other headers, cookies must be sent from your script (this is a protocol limiting output). This will require your place to call this function before any output, including
Once the cookies have been identified, they can visit the next page loaded with $ _cookie or $ http_cookie_vars array. Note that the Super global variable $ _cookie form applies to PHP's 4.1.0. The value of the cookie also exists in the $ _request array.
The code is as follows |
Copy Code |
BOOL Setcookie (String $name [, String $value [, int $expire = 0 [, String $path [, String $domain [, bool $secure = Fals e [, bool $httponly = FALSE]]]] |
*/
The code is as follows |
Copy Code |
function Makecookie ($var, $value, $life = 0, $prefix = 0)//Set Cookie { Global $cookiepre, $cookiedomain, $cookiepath, $timestamp, $_server; Setcookie ($prefix $cookiepre: "). $var, $value, $life? $timestamp + $life: 0, $cookiepath, $cookiedomain, $_server[' server_port '] = = 443? 1:0); } function clearcookies ()//Clear cookies { Global $uid, $username, $PW, $adminid; Makecookie (' auth ', ',-86400 * 365); $uid = $adminid = 0; $username = $PW = '; } |
Instance
The code is as follows |
Copy Code |
Makecookie (' n ', ' www.111cn.net '); Clear cookies Clearcookies (); Below Xing a support level two domain name cookie function bar. function setcookielive ($name, $value = ', $expire =0, $path = ', $domain = ', $secure =false, $httponly =false) { Set a cookie as usual, but also add it to $_cookie so the current page load has access $_cookie[$name] = $value; Return Setcookie ($name, $value, $expire, $path, $domain, $secure, $httponly); } |
Call method
code is as follows |
copy code |
setcookielive (' Webab ', ' 111CN ', Time () +86000, '/', ' 111cn.net '); //One entry cookie Setup method Setcookie ("Cookie[three]", "Cookiethree"); Setcookie ("Cookie[two]", "cookietwo"); Setcookie ("Cookie[one]", "Cookieone"); //After the page reloads, print them out if (isset ($_cookie[' cookie ')) { foreach ($_cookie [' Cookie '] as $name => $value) { echo $name: $value <br/> "; } } |