Recently in a Web site to write PHP background to find Setcookie This function is always unable to set the cookie normally, through Var_dump () found that the function return value is False, is clearly set unsuccessful, Google, found that Setcookie failure may have some reasons:
1. Cookies are disabled by the browser. Without checking, I'm certainly not disabled.
2. Using PHP's Setcookie () to create a cookie is the same as the Session_Start () that opens the session in PHP, and cannot have any HTTP header output before Setcookie (). I went to check the code and found the following code
Var_dump ($qOpenId); Setcookie (' Qopenid ', $openid, Time () + 30 * 24 * 3600, '/');
Decisive comment Var_dump ($OpenId) This line, test, success.
Personally, Setcookie should be directly set the contents of the HTTP header, so the front can not have any head output, Var_dump,echo anything can not have
Related articles:
Setcookie do not set the expiry time, set the path how to write?
PHP Setcookie Usage
Cookies set PHP Setcookie settings cookie usage and settings invalid problem