问题听起来像这样: 使用会话登录在我的本地主机上工作得很好,但是当完全相同的文件上传到我的主机(hostgator)时,会话不会或者,或者它们搞砸了。注销功能也不适用于主机。
我已经检查过,每个页面都有session_start();在里面。
即使我的logout.php看起来像这样,会话也不会被销毁:
<?php
session_start();
$_SESSION = array();
session_unset();
session_destroy();
header("location:index.php");
exit();
?>
有什么建议吗?
答案 0 :(得分:2)
我在Firebug的Firefox上注意到你的页面都被缓存了。你的会话工作正常,但你的页面被缓存,登录和注销相当混乱(搞砸了)。
禁用动态网页的HTTP缓存。
请参阅Firebug输出:
HTTP/1.1 304 Not Modified
Date: Thu, 14 Oct 2010 13:16:50 GMT
Server: Apache mod_fcgid/2.3.5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
Connection: Keep-Alive
Keep-Alive: timeout=5, max=100
Expires: Thu, 14 Oct 2010 16:16:50 GMT
Cache-Control: public, max-age=10800
GET / HTTP/1.1
Host: www.piataterenuri.info
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Cookie: PHPSESSID=55aea3f792334052dc673f85feb0b54a
If-Modified-Since: Wed, 13 Oct 2010 13:47:53 GMT
Cache-Control: max-age=0
PHP手册已经有一个关于如何禁用缓存的示例:
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>