1.

How to create and destroy cookies in PHP?

Answer»

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.

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);



Discussion

No Comment Found