浏览器关闭时PHP会话cookie将过期

Por*_*ich 3 php cookies wordpress session

我在Wordpress中工作,并在我的functions.php页面中有以下内容.

我有3种不同风格的阵列.我的cookie正在进行随机化.

if (isset($_COOKIE['style'])){
    $style = $_COOKIE['style'];
}
else {
    $style = ($rand[$stylearray]);
    setcookie('style',$style,time(),COOKIEPATH,COOKIE_DOMAIN,false); 
}
Run Code Online (Sandbox Code Playgroud)

我想设置它,以便我的cookie 在浏览器关闭时到期.但是,似乎在页面刷新(F5)上cookie过期.

有没有办法设置它,以便我的cookie只在浏览器关闭时到期?

Hov*_*ovo 6

http://www.w3schools.com/php/func_http_setcookie.asp

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
Run Code Online (Sandbox Code Playgroud)

所以

setcookie('style',$style, 0 , ...); 
Run Code Online (Sandbox Code Playgroud)

要么

setcookie('style',$style, '', ...); 
Run Code Online (Sandbox Code Playgroud)

必须工作.