In this tutorial, we will see how to store a minimum amount of data within the user’s browser itself using the PHP cookies.
What is a Cookie?
A cookie is a small text file that lets you store a small amount of information (nearly 4KB) on the user’s computer.
Each time with the same computer the browser requests a page to the server and all the information in the cookie is automatically sent to the server within the request.
And mostly cookie is frequently used to recognize the user. With the help of PHP, you can both create and retrieve cookie values.
How to set a Cookie in PHP
setcookie() function, we can create or set a cookie.
There are mostly all parameters are optional except the parameter of the name.
There are given below, all the parameters explanation of the php
|The name of the cookie.|
|The value of the cookie. The text file Do not store sensitive information since cookies value is stored on the user’s computer.|
|The expiry date in UNIX timestamp format. After finishing this time cookie will become inaccessible. The default value of cookie is 0 in .|
|Specify the path on the server for which the cookie will be available. If set to |
|Specify the domain for which the cookie value is available to e.g www.example.com.|
|This field, if present, indicates that the cookie should be sent only if a secure HTTPS connection exists.|