QuestionsPHP Cookies
mmWebetutorial Staff asked 3 months ago

A cookie is created with the setcookie() function.

$cook_nm = “victor”;
$cook_val = “this is cookies”;
setcookie($cook_nm, $ cook_val, time() + (86400 * 30), “/”); // 86400 = 1 day

For Check cookies existence:-

if(!isset($_COOKIE[$cook_nm])) {
echo “Cookie named ‘” . $ cook_nm. “‘ is not set”;
} else {
echo “Cookie ‘” . $ cook_nm. “‘ is set<br>”;
echo “Value = ” . $_COOKIE[$cook_nm];
}

To delete a cookie, use the setcookie() function with an expiration date

setcookie(“victor “, “”, time() – 3600); //3600 = 1 hour

Your Answer
Login
Enter email and password to comment or answer
Not the answer you are looking for? Browse other questions tagged or ask your own question.