簡體   English   中英

PHP session_id()在每個請求上刷新,$ _COOKIE ['PHPSESSID']為空

[英]PHP session_id() refresh on every request, $_COOKIE['PHPSESSID'] empty

我不知道為什么,但是嘗試了所有答案/谷歌。 情況如下:

本地主機代碼

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

結果:

整個應用頁面和頁面刷新時的session_id()一致。 $ _COOKIE ['PHPSESSID']與session_id()匹配

LIVE服務器

    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

檢查php.ini文件中的session.use_cookies。 必須設置為1。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM