The result encountered a problem, Setcookie set the cookie did not take effect, in the browser side also did not see. Check it out, it turns out that Setcookie is done through the header of the HTTP request response, and needs to be executed before the response content output is requested (just like other header settings).
In the case of error_reporting = E_all in php.ini, the following prompts will pop up after the output Setcookie:
Copy Code code as follows:
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 the development of the proposal set to Error_reporting = E_all easy to observe some anomalies.
Attach an example of Setcookie usage
a.php
Copy Code code as follows:
<?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
Copy Code code as follows:
<?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>