PHP transparently supports HTTP cookies. A cookie is a mechanism that stores data on a remote browser to track and identify users. Cookies can be set using the setcookie() or setrawcookie() functions.
Cookie is part of the HTTP header, so the setcookie() function must be called before other information is output to the browser, which is the same as the header() function The restrictions are similar. You can use the output buffer function to delay the output of the script until all cookies or other HTTP headers have been set as required. (Recommended learning: PHP Video Tutorial)
If "C" is included in variables_order, any cookie sent from the client will be automatically included in the $_COOKIE automatic global array. If you want to set multiple values for a cookie variable, you need to add the [] symbol after the cookie name.
According to the setting of register_globals, ordinary PHP variables can be created from cookies. However, relying on this feature is not recommended as this option is usually turned off for security reasons.
Setting new cookie ============================= <?php setcookie("name","value",time()+$int); /*name is your cookie's name value is cookie's value $int is time of cookie expires*/ ?> Getting Cookie ============================= <?php echo $_COOKIE["your cookie name"]; ?> Updating Cookie ============================= <?php setcookie("color","red"); echo $_COOKIE["color"]; /*color is red*/ /* your codes and functions*/ setcookie("color","blue"); echo $_COOKIE["color"]; /*new color is blue*/ ?> Deleting Cookie ============================== <?php unset($_COOKIE["yourcookie"]); /*Or*/ setcookie("yourcookie","yourvalue",time()-1); /*it expired so it's deleted*/ ?>
The above is the detailed content of PHP determines whether cookies are supported. For more information, please follow other related articles on the PHP Chinese website!