[英]Copying Cookie From Another Domain To My Domain
I'm making a cURL request from exampleA.com
to get its response header. 我正在从exampleA.com
发出cURL请求以获取其响应头。 So far so good, these are some of the data I get: 到目前为止一切顺利,这些是我得到的一些数据:
Array
(
[0] => sess=1; path=/; expires=Wed, 15-May-2013 09:25:29 GMT; domain=.exampleA.com; HttpOnly
[1] => .........
)
Now this is the hard part for me, I want to set the cookie to my own domain exampleB.com
, the same as how I got it from exampleA.com
. 现在这对我来说很难,我想将cookie设置为我自己的域exampleB.com
,就像我从exampleA.com
它一样。
Using Firebug this is the Response Header in exampleA.com
: 使用Firebug这是exampleA.com
的响应标头:
Set-Cookie:uuid2=4511997856767122744; path=/; expires=Mon, 12-Aug-2013 09:21:38 GMT; domain=.exampleA.com; HttpOnly
So I need to set the cookie to the same values, but under the domain of exampleB.com
. 所以我需要将cookie设置为相同的值,但是在exampleB.com
的域下。 How do I do that? 我怎么做?
$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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.