2013-05-14 54 views
1

我正在從exampleA.com發出cURL請求以獲取其響應頭。到目前爲止好,這些都是一些數據,我得到:將Cookie從另一個域複製到我的域

Array 
(
    [0] => sess=1; path=/; expires=Wed, 15-May-2013 09:25:29 GMT; domain=.exampleA.com; HttpOnly 
    [1] => ......... 
) 

現在,這對我來說是最困難的部分,我想該cookie設置爲我自己的域名exampleB.com,同我如何從得到它exampleA.com

用Firebug這是響應頭在exampleA.com

Set-Cookie:uuid2=4511997856767122744; path=/; expires=Mon, 12-Aug-2013 09:21:38 GMT; domain=.exampleA.com; HttpOnly 

所以我需要cookie中設置爲相同的值,但exampleB.com域下。我怎麼做?

+2

您無法從其他域讀取cookie。 – ChamingaD 2013-05-14 10:06:05

+0

即時通訊使用CURL從domainX獲取響應頭。 – 2013-05-14 10:18:18

+0

@crypticツ,你是正確的,即時通訊使用CURL。 #ChamingaD爲什麼downvote? – 2013-05-14 10:19:53

回答

4
$ch = curl_init('http://www.google.com/'); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$response = curl_exec($ch); 
curl_close($ch); 

preg_match('/Set-Cookie:[^\r\n]+/', $response, $match); // extract cookie header 
$cookie_header = preg_replace('/domain=[^;\r\n]+/', 'domain=.mydomain.com', $match[0]); // replace old domain with your domain 

//echo $cookie_header; 
header($cookie_header); // set cookie header 
+0

對不起,我想知道的是如何設置我從捲曲到我自己的域的cookie。請閱讀我的帖子,即時通訊設置cookies就像從domainY設置一樣困難。 – 2013-05-14 10:35:08

+0

@WonderingCoder請參閱編輯,只需將「.mydomain.com」替換爲您的域。 – 2013-05-14 10:41:37

+1

你的解決方案男人!我愛你<3。 HAHAH。非常感謝你的幫助。 – 2013-05-14 10:56:15

相關問題