php $_COOKIE simple application example_PHP tutorial

WBOY
Release: 2016-07-13 16:59:13
Original
920 people have browsed it

COOKIE is before the content of the web page is sent. Send the message first. That is to say. There cannot be any HTML code, echo, etc. before this, even a space is not allowed. .

Cookies are placed before web content is sent. Send the message first. That is to say. There cannot be any html code, echo, etc. before this, even a space is not allowed. .

In the PHP tutorial, you need to use the setcookie function to register the cookie variable. Your code above does not register the cookie variable. How could it possibly be delivered? The correct way to write it is as follows:

*/
$status=0;                                                                                                                                                                                                                            if(isset($_cookie['mytstcky'])&&($_cookie['mytstcky']=="chocchip")) $status=1; //If the variable has been set
if(!isset($_get['cchk'])) //If the variable is not set
{
setcookie("mytstcky","chocchip"); //Send cookie information
header("location:$php_self?cchk=1"); //Send header
exit; //End php code
}
?>

cookie check

cookie check status:
printf('%s
;',$status ? "00ff00" : "ff0000",$status ? "passed!" : "failed! "); // Output different content according to conditions
?>


http://www.bkjia.com/PHPjc/631354.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631354.htmlTechArticleCOOKIE is before the web page content is sent. Send the message first. That is to say. There cannot be any HTML code, echo, etc. before this, even a space is not allowed. . ...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template