PHP $_COOKIE Convert to PHP $_COOKIE
Aug 27, 2023 pm 02:01 PMIntroduction
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.
What are cookies?
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
Syntax
setcookie(name, value, expire, path, domain, security);
Parameters
- Name - The name of the cookie being stored.
- Value - Sets the value of the specified variable. < li>Expiration - Specifies a time in the future (in seconds) since January 1, 1970 00:00:00 GMT.
- Path - Cookie valid directory.
- Domain - Specifies a domain name within a very large domain.
- Security − 1 means HTTPS. Regular HTTP defaults to 0.
Cookie Example
<?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
Example
<?php $arr=$_COOKIE; foreach ($arr as $key=>$val); echo "<h2>$key=>$val </h2>"; ?>
Output
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!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon
