2016-09-26 91 views
3

當前我想訪問需要Cookie的Url。未使用Cookie它重定向到其他Url。我嘗試在請求標題中設置Cookie,但僅獲取響應標題中的Cookie。不知道爲什麼會發生。Cookie未在標題請求文件中設置

這是響應頭:

Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0 
    Content-Type:text/html; charset=UTF-8 Date Mon, 26 Sep 2016 11:52:59 GMT Expires 
    Thu, 19 Nov 1981 08:52:00 GMT 
    Location  
    quotev3.php?sub=compare 
    Pragma 
    no-cache 
    Server 
    nginx 
    Set-Cookie 
    PHPSESSID=e2dnbfjvhi29e7qnkm0jbnekc4; path=/ 
    country=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0 
    X-Firefox-Spdy 
    h2 

請求頭

Accept 
*/* 
Accept-Encoding 
gzip, deflate, br 
Accept-Language 
en-US,en;q=0.5 
Connection 
keep-alive 
Content-Length 
119 
Content-Type  
application/x-www-form-urlencoded 
Host  
www.parcelmonkey.co.uk 
Origin 
null 
User-Agent 
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0 

我在頭文件是一樣設置一個cookie。

$cookie=$_COOKIE['PHPSESSID']; 
ob_start(); 
header('Access-Control-Allow-Origin: *'); 
header('Access-Control-Allow-Origin: *'); 
header('Access-Control-Allow-Methods: GET, POST, OPTIONS'); 
header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With'); 
header('Access-Control-Allow-Credentials: true'); 
header('Cookie:'.$cookie); 

的任何解決方案將是非常Appriciated.Thanks

回答

1

你需要指定cookie的關鍵,不只是它的價值。

此外,該命令是Set-Cookie而不是Cookie

使用setcookie功能,或header這樣的:

setcookie('PHPSESSID', $cookie); 

header("Set-Cookie: PHPSESSID={$cookie};");