Setting a cookie value immediately – PHP

print
The way to set a cookie:

setcookie("COOKIE NAME", "COOKIE VALUE", time() + 3600 * 8 * 7);

This cookie will be in place when the page next refreshes/loads;

To work with an immediate value of the cookie, add this as well:

$_COOKIE['COOKIE NAME']= COOKIE VALUE;
setcookie("COOKIE NAME", "COOKIE VALUE", time() + 3600 * 8 * 7);

Using the above method will shove the value of the cookie into the session variable version, as well as writing it where it should be ready for a page reload.

Share this post:
Related Posts
php-banner
A list of PHP dateTime method date and time formatting option
php-banner
PHP ternary operators and how to use them

Leave a Comment