setcookie("TestCookie", $value, time()+3600, "/~rasmus/", "example.com", 1);是见是一个time()+3600 不知,这段说明是啥意思,看看是不是这个原因“ expire The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. In other words, you'll most likely set this with the time() function plus the number of seconds before you want it to expire. Or you might use mktime(). time()+60*60*24*30 will set the cookie to expire in 30 days. If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes). Note: You may notice the expire parameter takes on a Unix timestamp, as opposed to the date format Wdy, DD-Mon-YYYY HH:MM:SS GMT, this is because PHP does this conversion internally. ”
不知,这段说明是啥意思,看看是不是这个原因“
expire
The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. In other words, you'll most likely set this with the time() function plus the number of seconds before you want it to expire. Or you might use mktime(). time()+60*60*24*30 will set the cookie to expire in 30 days. If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes).
Note: You may notice the expire parameter takes on a Unix timestamp, as opposed to the date format Wdy, DD-Mon-YYYY HH:MM:SS GMT, this is because PHP does this conversion internally.
”
参数 描述
name 必需。规定 cookie 的名称。
value 必需。规定 cookie 的值。
expire 可选。规定 cookie 的有效期。
path 可选。规定 cookie 的服务器路径。
domain 可选。规定 cookie 的域名。
secure 可选。规定是否通过安全的 HTTPS 连接来传输 cookie。
现设置cookie如下:
setcookie('php_dbgs6_abc', 'value', time() + 24 * 3600, '/', '1.cn');
结果无效(IE下不行,FF下是可以的)。setcookie('php_dbgs6_abc', 'value', time() + 24 * 3600, '/');
这样有效(IE与FF都可以)。
s1.php<?php
//$expire = gmdate('D, d-M-Y H:i:s \\G\\M\\T', time() + 24 * 3600);
//$domain = '; domain=' . $_SERVER['HTTP_HOST'];
//header('Set-Cookie: php_dbgs6_abc=121111ie; expires=' . $expire . '; path=/' . $domain . '; HttpOnly', false); // 无效//setcookie('php_dbgs6_abc', '121111ie', time() + 24 * 3600, '/', '.' . $_SERVER['HTTP_HOST']); // 无效
//setcookie('php_dbgs6_abc', '121111ie', time() + 24 * 3600, '/', $_SERVER['HTTP_HOST']); // 无效
setcookie('php_dbgs6_abc', '121111ie', time() + 24 * 3600, '/'); // 有效
print_r($_COOKIE);
?>
<a href="s2.php">S2</a>
s2.php<?php
setcookie('php_dbgs6_abc', '', time() - 24 * 3500);
print_r($_COOKIE);
?>
<a href="s1.php">S1</a>
上述几种方式看看究竟是哪里出了问题。