Super global $_COOKIEStores variables passed to the current script along with the HTTP request in the form of cookies. $HTTP_COOKIE_VARS also contains the same information, but is not super-global and is now deprecated.
Cookies are text files stored on client computers by the server for usage tracking purposes. PHP transparently supports HTTP cookies. Cookies are usually set in HTTP headers. JavaScript can also set cookies directly on the browser.
The server script sends a set of cookies to the browser. It stores this information locally on your computer for future use. The next time the browser makes any request to the web server, it will send this cookie information to the server, which uses the information to identify the user.
PHP contains the setcookie function to create a cookie object and send it to the client along with the HTTP response.
setcookie(name, value, expire, path, domain, security);
<?php if (isset($_COOKIE['username'])) echo "<h2>Cookie name is already set with value: " . $_COOKIE['username'] . "</h2>"; else{ setcookie("username", "Anil"); echo "<h2>Cookie is now set </h2>"; ?>
Retrieve cookies on subsequent visits from the client
<?php $arr=$_COOKIE; foreach ($arr as $key=>$val); echo "<h2>$key=>$val </h2>"; ?>
The browser will Display results similar to the following
username=>Anil
To delete a cookie, set the cookie to an expired date
The above is the detailed content of PHP $_COOKIE Convert to PHP $_COOKIE. For more information, please follow other related articles on the PHP Chinese website!