$_COOKIE
$_COOKIE
Cookie
Cookie is a small file that the server embeds on the user's computer. Each time the computer opens a webpage, the server will send a cookie to the computer. PHP contains setcookie function to create a cookie object to be sent to the client along with HTTP response.
Creating Cookies with PHP
A cookie can be created with the setcookie() function.
Syntax:
Parameters
- Name − Name of the cookie stored.
- Value − This sets the value of the named variable.
- Expiry − This specifes a future time in seconds since 00:00:00 GMT on 1st Jan 1970.
- Path − Directories for which the cookie is valid.
- Domain − Specifies the domain name in very large domains.
- Security − 1 for HTTPS. Default 0 for regular HTTP.
Example:
Modifying a Cookie
To modify a cookie, just set the cookie again using the setcookie() function.
Example:
Delete a Cookie
To delete a cookie, we need to use the setcookie() function with a date that has already expired.
Example: