douzhi7082 2013-05-14 09:54
浏览 53
已采纳

将Cookie从另一个域复制到我的域

I'm making a cURL request from exampleA.com to get its response header. 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.

Using Firebug this is the Response Header in 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. How do I do that?

  • 写回答

1条回答 默认 最新

  • donglun2024 2013-05-14 10:29
    关注
    $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:[^
    ]+/', $response, $match); // extract cookie header
    $cookie_header = preg_replace('/domain=[^;
    ]+/', 'domain=.mydomain.com', $match[0]); // replace old domain with your domain
    
    //echo $cookie_header;
    header($cookie_header); // set cookie header
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 matlab求解平差
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现