How to let Curl use same cookie as the browser from PHP

前端 未结 6 1079
太阳男子
太阳男子 2020-12-14 11:02

I have a PHP script that does an HTTP request on behalf of the browser and the outputs the response to the browser. Problem is when I click the links from the browser on thi

6条回答
  •  生来不讨喜
    2020-12-14 11:39

    From curl_setopt:

    By default, libcurl always stores and loads all cookies, independent if they are session cookies or not.

    However you may need to set cookies directly, which can be done using:

    curl_setopt($ch, CURLOPT_COOKIE, 'foo=bar');
    

    Which is the same as the Set-Cookie HTTP header. Check you're not using curl_setopt($ch, CURLOPT_COOKIESESSION, true) as this will make libcurl ignore some cookies.

提交回复
热议问题