PHP Tutorial Setting cookies and cleaning cookies method
/*
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 requires your place to call this function before any output, including <html> and <head> tags, as well as any spaces.
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.
BOOL Setcookie (String $name [, String $value [, int $expire = 0 [, String $path [, String $domain [, bool $secure = False [, BOOL $httponly = false]]]/
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
Makecookie (' n ', ' www.jzread.com ');
Clear cookies
Clearcookies ();
Below Xing a support level two domain name cookie function.
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 Super-delegates access
$_cookie[$name] = $value;
Return Setcookie ($name, $value, $expire, $path, $domain, $secure, $httponly);
}
Call method
Setcookielive (' Webab ', ' 111CN ', Time () +86000, '/', ' jzread.com ');
One Entry level 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[ ' Cookies '] as $name => $value) {
echo $name: $value <br/>n;
}
}