dongwen3437 2012-02-08 04:47
浏览 138
已采纳

PHP curl,保留会话

I'm making an app that scrapes data off a site, formats it as needed, and displays it to the user. Now, the site doesn't allow cross-site script requests, so I'm using PHP's curl to retrieve the page.

  • With a browser, the site gives you a cookie when you first visit, asking you to log in, and on subsequent requests will give you the actual page you requested.

  • With PHP's curl, the site will just give me the page asking me to log in. And, I presume, give my PHP server a cookie.

How can I save this cookie and present it on subsequent requests?

  • 写回答

3条回答 默认 最新

  • dpxw7293 2012-02-08 04:57
    关注

    use a few setopts to set the cookie.

    Example:

    $ch=curl_init();
    curl_setopt($ch, CURLOPT_COOKIEFILE, "c:/cookies/cookie.txt");
    curl_setopt($ch, CURLOPT_COOKIEJAR, "-");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器