douzi1991 2013-10-01 23:29
浏览 64
已采纳

PHP - getCookies()为空但getHeaders()没有

I am trying to parse the response header cookies for a GET request.

For some reason, getCookies() is empty! I get a 200 Response but for some reason cannot access the cookies. I'm able to get the headers, though.

Is it possible this website is hiding its cookies? What are some ways to retrieve hidden cookies?

$request = new HTTP_Request2($url, HTTP_Request2::METHOD_GET);
$request2 = new HTTP_Request2($newUrl, HTTP_Request2::METHOD_POST);

$response = $request->send();

foreach ($response->getCookies() as $c)
{
   request2->addCookies($c['name'], $c['value']);
}

Cookies are being set with Javascript via (I peeked into their JS code)

<script language="JavaScript">
document.cookie="MRHCId="+Math.round((new Date()).getTime()/1000)+"_0_3600; path=/"; 
</script>

How can I send this cookie along with my PHP Post request?

  • 写回答

1条回答 默认 最新

  • duanlin6989 2013-10-02 20:04
    关注

    Posting my comment as an answer in case you want to close the question:

    Is it possible that the website doesn't use cookies? They are not required for a website to operate or anything. Or perhaps, it just doesn't set them through the headers? They can be set through javascript. And I wouldn't be surprised with all the JS heavy websites out there. Also, there is no such thing as a "Hidden Cookie".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何实现从tello无人机上获取视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决