The PHP settings cookie can use the Setcookie function or the header function. You need to pay attention to the order of the strings when using the header method, and unexpected problems may occur if the order is incorrect. The correct order is
Name=value; [Expires=date; [Path=path]; [Domain=domainname]; [Secure]]
For example: Under Netingcn.com, set a cookie named CookieName, with a value of cookievalue, and an expiration time of one year
Header ("Set-cookie:cookiename=cookievalue; Expires= ". Gmstrftime ("%A,%d-%b-%y%h:%m:%s GMT", Time () + (86400 * 365)). path=/; Domain=netingcn.com ');
If you put domain, path in front of the expires, when Firefox through the Httpfox view, found that the expiration time is "end of the session", but after exiting the browser to reopen, found that the cookie still exists, Chrome also shows similar. Although browsers eventually set a one-year expired cookie, domain information is the full domain of the current page, not the top-level domain of the setting. So be sure to pay attention to the order.
In addition, if you set multiple cookies in header mode, you need to set the second parameter of the header to false, and the following is the header function declaration:
void header (String string [, bool replace [, int http_response_code]])
The second parameter, replace, indicates whether to replace the previous similar header or to add a header of the same type. The default is replace, but if you set it to FALSE, you can force multiple homogeneous headers to be sent.
Http://www.netingcn.com/php-header-set-cookie.html