19 May 2008

一个 PHP setcookie() 的小问题

碰到一个奇怪的问题:

同一个 Apache/PHP Server,同一段 PHP 代码,在 Firefox 里可以成功设置 cookie,而 Opera/IE7 里却无法设置。

怎么也想不明白,请教 Google, 在 php 的官方 setcookie() 手册页发现了问题的所在:
If you are having issues with IE7 and setcookie(), be sure to verify that the cookie is set via http for http sites, and https for https site.

Also, if the time is incorrect on your server, IE7 will also disallow those cookies from being set.

(From: http://www.php.net/manual/en/function.setcookie.php#72313

我的问题出在时间上,我的 Server 时间现在还停留在 1999 年 XD。修改时间后,Opera/IE 都可以设置 cookie 了。

由于对 php 所知不多,真正的原因我也说不上来,期待 php 高手答疑解惑。