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

后端 未结 2 1265
伪装坚强ぢ
伪装坚强ぢ 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.

提交回复
热议问题