1

我不知道为什么,但尝试了所有答案/google ..我什么也没找到。情况如下:

本地主机代码

    session_start();
    echo session_id();
    print_r($_COOKIE['PHPSESSID']);

结果:

跨应用程序页面和页面刷新时一致的 session_id()。$_COOKIE['PHPSESSID'] 匹配 session_id()

实时服务器

    session_start();
    echo session_id();
    print_r($_COOKIE['PHPSESSID']);

结果:

session_id() 在每次请求、页面重新加载或访问另一个页面时都会更改。$_COOKIE['PHPSESSID'] 始终为 NULL/空。使用相同的代码,在页面顶部。没有任何其他内容。

这个问题让我很头疼,哪个服务器配置或错误可能导致这个问题?为什么 PHPSESSID cookie 是空的,我相信这也与 session_id() 在每个请求上被重置有关?

任何帮助请大家!

编辑:我在本地远程服务器上制作了一个简单的 3 行测试文件。它与我的代码无关。$_COOKIE['PHPSESSID'] 仍然是空的,并且每次刷新时都会在实时主机上发生新的 session_id()。

ERROR_REPORTING SET TO ALL 我在现场主机上得到了这个:

Notice: Undefined index: PHPSESSID in /home/vivaplug/public_html/dev/wp-content/plugins/test.php on line 5

谷歌浏览器标题

本地主机

Request URL:http://localhost/wp-content/plugins/test.php
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Cookie:PHPSESSID=68b7m4arpsacks4aetgmd3rs93
Host:localhost
Pragma:no-cache
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
Response Headersview source
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Type:text/html
Date:Tue, 05 Nov 2013 07:10:51 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=5, max=100
Pragma:no-cache
Server:Apache/2.4.4 (Win32) PHP/5.4.16
Transfer-Encoding:chunked
X-Powered-By:PHP/5.4.16

删除服务器

Request URL:http://vivaplugins.com/dev/wp-content/plugins/test.php
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Host:vivaplugins.com
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
Response Headersview source
Age:0
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Content-Encoding:gzip
Content-Type:text/html
Date:Tue, 05 Nov 2013 07:07:49 GMT
Pragma:no-cache
Server:Advanced Hosting by http://www.unixy.net/varnish
Transfer-Encoding:chunked
Vary:Accept-Encoding
Via:1.1 varnish
X-Cache:HIT
X-Cache-Hits:2
X-Cacheable:YES
X-Powered-By:PHP/5.4.20
X-Varnish:1984840969 1984839805
4

1 回答 1

0

检查 php.ini 文件中的 session.use_cookies。必须设置为 1。

于 2013-11-05T07:27:48.920 回答