将Cookie从另一个域复制到我的域
我正在从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
域下。我怎么做?
$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
对不起,我想知道的是如何设置我从卷曲到我自己的域的cookie。请阅读我的帖子,即时通讯设置cookies就像从domainY设置一样困难。 – 2013-05-14 10:35:08
@WonderingCoder请参阅编辑,只需将“.mydomain.com”替换为您的域。 – 2013-05-14 10:41:37
你的解决方案男人!我爱你 2013-05-14 10:56:15
您无法从其他域读取cookie。 – ChamingaD 2013-05-14 10:06:05
即时通讯使用CURL从domainX获取响应头。 – 2013-05-14 10:18:18
@crypticツ,你是正确的,即时通讯使用CURL。 #ChamingaD为什么downvote? – 2013-05-14 10:19:53