+add a note
User Contributed Notes 12 notes
walterquez ¶
12 years ago
Instead of this:
<?php setcookie( "TestCookie", $value, time()+(60*60*24*30) ); ?>
You can this:
<?php setcookie( "TestCookie", $value, strtotime( '+30 days' ) ); ?>
Bachsau ¶
12 years ago
Want to remove a cookie?
Many people do it the complicated way:
setcookie('name', 'content', time()-3600);
But why do you make it so complicated and risk it not working, when the client's time is wrong? Why fiddle around with time();
Here's the easiest way to unset a cookie:
setcookie('name', 'content', 1);
Thats it.
Anonymous ¶
4 years ago
Just an example to clarify the use of the array options, especially since Mozilla is going to deprecate / penalise the use of SameSite = none, which is used by default if not using array options.
<?php
$arr_cookie_options = array (
'expires' => time() + 60*60*24*30,
'path' => '/',
'domain' => '.example.com', // leading dot for compatibility or use subdomain
'secure' => true, // or false
'httponly' => true, // or false
'samesite' => 'None' // None || Lax || Strict
);
setcookie('TestCookie', 'The Cookie Value', $arr_cookie_options);
?>