会话在外部主机上混乱 [英] Sessions get messed up on external host

查看:85
本文介绍了会话在外部主机上混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题听起来像这样: 使用会话登录可以在我的本地主机上完美运行,但是当完全相同的文件上载到我的主机(hostgator)时,会话无法连接,或者混乱.此外,注销功能在主机上不起作用.

The problem sounds like this: The log-in using sessions works perfect on my localhost, but when the EXACTLY same files are uploaded to my host (hostgator), the sessions don't or, or they get messed up. Also the log-out feature doesn't work on the host.

我已经检查过了,每个页面都有session_start();在里面.

I've checked and every page has the session_start(); inside it.

即使我的logout.php看起来像这样,会话也不会被破坏:

The session is not destroyed, even if my logout.php looks like this:

<?php
session_start(); 
$_SESSION = array();
session_unset();
session_destroy();
header("location:index.php");
exit();
?>

有什么建议吗?

推荐答案

我在使用Firebug的Firefox上注意到所有页面都已缓存.您的会话工作正常,但是页面被缓存,使登录和注销都很(混乱).

I noticed on Firefox with Firebug that your pages are all cached . Your session is working fine, but your page are cached, making login and logout quite (messed up).

为动态页面禁用HTTP缓存.

Disable HTTP caching for your dynamic pages.

请参阅Firebug输出:

See Firebug output:

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 manual has already an example on how to disable caching:

http://php.net/manual/en/function.header.php

<?php

header("Cache-Control: no-cache, must-revalidate"); 
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

?>

这篇关于会话在外部主机上混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆