I am working in Wordpress and have the following in my functions.php page.
I have an array of 3 different styles. My cookie is doing the randomizing.
if (isset($_COOKIE['style'])){
$style = $_COOKIE['style'];
}
else {
$style = ($rand[$stylearray]);
setcookie('style',$style,time(),COOKIEPATH,COOKIE_DOMAIN,false);
}
I want to set it so that my cookie ONLY expires when browser closes. However, it seems that on page refresh(F5) the cookie expires.
Is there a way to set it so that my cookie only expires on browser close?
The http://www.w3schools.com/php/func_http_setcookie.asp says
Optional. Specifies when the cookie expires. The value: time()+86400*30,
will set the cookie to expire in 30 days. If this parameter is omitted
or set to 0, the cookie will expire at the end of the session
(when the browser closes). Default is 0
So
setcookie('style',$style, 0 , ...);
or
setcookie('style',$style, '', ...);
must work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With