curl Error : maximum redirects followed , 这种问题的一种原因 .

在stack overflow 上查找到有些网站上需要返回一些cookie的,所以当我们curl当相应的网站时,必须要将返回的cookie保存起来。


 $cookie tempnam ("/tmp""CURLCOOKIE");

 curl_setopt$chCURLOPT_COOKIEJAR$cookie );


tempnam(dir,prefix)

tempnam() 函数创建一个具有唯一文件名的临时文件。若成功,则该函数返回新的临时文件名。若失败,则返回 false。


PHP cURL 的 option 中有兩項名字很接近 - CURLOPT_COOKIEFILE 和 CURLOPT_COOKIEJAR , PHP: curl_setopt - Manual 裡對 CURLOPT_COOKIEFILE 和 CURLOPT_COOKIEJAR 的介紹分別是︰


CURLOPT_COOKIEFILE
The name of the file containing the cookie data. The cookie file can be in Netscape format, or just plain HTTP-style headers dumped into a file.

CURL 要發出的 HTTP Request 的 Cookie 存放在哪


CURLOPT_COOKIEJAR
The name of a file to save all internal cookies to when the connection closes.

CURL 收到的 HTTP Response 中的 Set-Cookie 要存放在哪.


你可能感兴趣的:(PHP)