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条)

报告相同问题?