PHP tutorial setting cookie and clearing cookie
/*
The setcookie () function defines the rest of the HTTP header sent by a cookie. Like other headers, cookies must be sent from your script before (this is a protocol limit output ). This requires any output before you call this function, including the <HTML> and
Once the cookies are determined, they can access the next page to load the $ _ cookie or $ http_cookie_vars array. Note that, for example, the super global variable $ _ cookie is applicable to PhP 4.1.0. The cookie value 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 ('20140901', 'www .111cn.net ');
// Clear cookie
Clearcookies ();
// A second-level domain name Cookie function is supported below.
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
Setcookielive ('webb', '111cn', time () + 86000, '/', '111cn. net ');
// Entry-level cookie setting method
Setcookie ("Cookie [three]", "cookiethree ");
Setcookie ("Cookie [two]", "cookietwo ");
Setcookie ("Cookie [one]", "cookieone ");
// After the page reloads, print them out
If (isset ($ _ cookie ['cookies']) {
Foreach ($ _ cookie ['cooker'] as $ name => $ value ){
Echo "$ name: $ value <br/> N ";
}
}