PHPsetcookie setting Cookie usage (and invalid settings ). As a result, the setcookie setting does not take effect and is not displayed on the browser. After checking, it turns out that setcookie is completed through the Header of the HTTP request response. as a result, a problem occurs. the setcookie setting does not take effect and is not displayed on the browser end. After checking, it turns out that setcookie is implemented through the HTTP request response Header and needs to be executed before the request response content is output (just like other Header settings ).
In the case of error_reporting = E_ALL in php. ini, the following prompt is displayed when the output content is followed by setcookie:
The code is as follows:
Warning: Cannot modify header information-headers already sent by (output started at C: \ xampp \ htdocs \ B. php: 2) in... On line...
But since php. ini was set to error_reporting = E_ALL &~ E_NOTICE, so there is no prompt, so it is recommended to set error_reporting = E_ALL during development to facilitate observation of some exceptions.
An example of setcookie usage is provided.
A. php
The code is as follows:
Setcookie ("page", "a. php ");
$ Page = $ _ COOKIE ["page"]? $ _ COOKIE ["page"]: "unknown ";
Echo "From". $ page ."
";
?>
This is a. php. Go to B. php
B. php
The code is as follows:
Setcookie ("page", "B. php ");
$ Page = isset ($ _ COOKIE ["page"])? $ _ COOKIE ["page"]: "unknown ";
Echo "From". $ page ."
";
?>
This is B. php. Go to a. php
Bytes. After checking, it turns out that setcookie is completed through the HTTP request response Header ,...