How do I save cookies from a response to a cURL request using php?

后端 未结 2 1255
伪装坚强ぢ
伪装坚强ぢ 2020-12-15 07:40

Im using curl through php to fetch a url. I am successfully able to download the page, headers and all. However, the cookies returned by any page do not get saved to the spe

相关标签:
2条回答
  • 2020-12-15 08:29

    Thanks everyone for all the help. However, the problem was something else entirely. I probably should have mentioned that I am working on a Windows server and cURL was unable to read the path to cookie.txt.

    Using:

    curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt');
    

    instead of:

    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    

    solved the problem.

    0 讨论(0)
  • 2020-12-15 08:36

    Use an absolute path to the cookie jar file so that you're sure where it is saved and thus you know you have the right permission to write there.

    curl stores all cookies it knows of to the file, including so called session cookies (that are without an expiry time)

    0 讨论(0)
提交回复
热议问题