How to create and destroy cookies in PHP?
A cookie is a small file that stores on user's browsers. It is used to store users information. We can create and retrieve cookie values in PHP.
A cookie can be created with the setcookie()
function in PHP.
BY Best Interview Question ON 25 Jan 2019
Example
Create Cookie
$cookie_name = "username";
$cookie_value = "Umesh Singh";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
Update Cookie
$cookie_name = "username";
$cookie_value = "Alex Porter";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
Delete Cookie
setcookie("username", "", time() - 3600);