在报头请求文件中没有设置cookie


Cookies are not Set in Header Request file

目前我想访问需要cookie的Url。没有Cookie,它重定向到其他Url。我尝试在请求头中设置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); 

任何解决方案将非常感激。由于

您需要指定cookie的键,而不仅仅是它的值。

同样,命令是Set-Cookie而不是Cookie

使用setcookie功能,或header如下:

setcookie('PHPSESSID', $cookie);

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