What is a Cookie?
How To Set The Cookie
setCookie('user','name',time());
<?php
$value = 'CodeHubDeep';
setcookie("Cookie_Name", $value);
setcookie("Cookie_Name", $value, time()+7200); /* expire in 2 hour */
setcookie("Cookie_Name", $value, time()+7200, "/CodeHubDeep/", "https://codehubdeep.blogspot.com/", 1);
?>
This logic will be useful in case of Remember me.
How to expire Cookie :
since timestamp is independent unit and time cannot be < 0 hence timestamp cannot be destroy .
<?php
setcookie("TestCookie", "", time() - 7200);
setcookie("TestCookie", "", time() - 7200, "/CodeHubDeep/", "https://codehubdeep.blogspot.com/", 1);
?>
How to replace the existing Cookie :
there is no way to update a cookie. Just set (again) this cookie using setcookie.
setCookie('user','new_value',time()-300) // 12:35
<?php
$cookie_name = 'CodeHubDeep';
$cookie_value = 'TheBestEducationalWebsite';
setcookie($cookie_name, $cookie_value, time() -300, '/');
?>
How To Print an Individual Cookie :
<?php echo $_COOKIE["Cookie_Name"]; ?>
How To Debug/Test is to View All Cookies :
<?php print_r($_COOKIE); ?>
0 Comments