我无法弄清楚为什么,但尝试了所有答案/ 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
Google Chrome标头
LOCALHOST
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
答案 0 :(得分:0)
检查php.ini文件中的session.use_cookies。必须设置为1。