Cookie is the information sent before the webpage content is sent. that is to say, no html code or echo can be found before the cookie is sent. even a space is not allowed in
Cookie is the information sent before the webpage content is sent. that is to say, there cannot be any html code or echo before this, and even a space is not allowed.
In php, you need to use the setcookie function to register the cookie variable. your code above does not register the cookie variable. how can it be sent? the correct syntax is as follows:
- */
- $ Status = 0; // define the status
- If (isset ($ _ cookie ['mytacky ']) & ($ _ cookie ['mytacky'] = "chocchip") $ status = 1; // if the variable has been set
- If (! Isset ($ _ get ['cchk']) // if no variable is set
- {
- Setcookie ("mytstcky", "chocchip"); // send cookie information
- Header ("location: $ php_self? Cchk = 1 "); // send the header
- Exit; // end the php code
- }
- ?>
-
- Cookie check
- Cookie check status:
- Printf ('% s
; ', $ Status? "00ff00": "ff0000", $ status? "Passed! ":" Failed! "); // Output different content according to the condition
- ?>
-
-