The result is a problem, Setcookie set the cookie does not take effect, not seen on the browser side. Check it out, it turns out that Setcookie is done by the header of the HTTP request response and needs to be executed before the output of the request response content (as with other header settings).
In the case of error_reporting = E_all in php.ini, the following prompts will be displayed after the output is Setcookie:
Warning:cannot Modify header Information–headers already sent by (output started at c:\xampp\htdocs\b.php:2) in ... on Li Ne ...
But because at that time php.ini set to error_reporting = E_all & ~e_notice, so there is no hint, so when the development is recommended to set error_reporting = E_all to facilitate the observation of some anomalies.
Attach a Setcookie usage instance
a.php
<?php Setcookie ("page", "a.php"); $page = $_cookie["page"]? $_cookie["page"]: "Unknown"; echo "from". $page. "<br/><br/>";?> this is a.php. Go to <a href= "b.php" >b.php</a>
b.php
<?php Setcookie ("page", "b.php"); $page = isset ($_cookie["page"])? $_cookie["page"]: "Unknown"; echo "from". $page. "<br/><br/>";?> this is b.php. Go to <a href= "a.php" >a.php</a>
The above describes the cookies set PHP Setcookie settings cookie usage and settings are invalid, including the content of the cookie settings, I hope that the PHP tutorial interested in a friend to help.
Related articles:
Setcookie do not set the expiry time, set the path how to write?
PHP Setcookie Usage
PHP Setcookie function invalidation