當進入網站時,它設置會話cookie,並重定向到本身。
問題:
當使用curl與FOLLOW_RELOCATION
和COOKIE_SESSION
,它不重定向後適用的cookie,並以最大的限度重定向錯誤達到結束。
代碼:
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_INTERFACE, $ip);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
詳細輸出:
* About to connect() to www.thesite.org port 80 (#0)
* Trying x.x.x.254... * Name 'x.x.29.61' family 2 resolved to 'x.x.29.61' family 2
* Local port: 0
* connected
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET/HTTP/1.1
Host: www.thesite.org
Accept: */*
< HTTP/1.1 302 Moved Temporarily
< Date: Wed, 31 Jul 2013 15:14:05 GMT
< Server: Apache
< cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< pragma: no-cache
< expires: Mon, 17 Jul 1978 05:00:00 GMT
< Last-Modified: Wed, 31 Jul 2013 15:14:05 GMT
< Set-Cookie: JSESSIONID=0A2488FF811CCDAB6A6C95C12AA3F4F8.DB4B9335DF549E1FCF56CF5BD8; Path=/
< Location: http://www.thesite.org/
< Content-Length: 0
< Vary: Accept-Encoding
< Content-Type: text/html
<
* Connection #0 to host www.thesite.org left intact
* Issue another request to this URL: 'http://www.thesite.org/'
* Re-using existing connection! (#0) with host www.thesite.org
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET/HTTP/1.1
Host: www.thesite.org
Accept: */*
< HTTP/1.1 302 Moved Temporarily
< Date: Wed, 31 Jul 2013 15:14:06 GMT
< Server: Apache
< cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< pragma: no-cache
< expires: Mon, 17 Jul 1978 05:00:00 GMT
< Last-Modified: Wed, 31 Jul 2013 15:14:06 GMT
< Set-Cookie: JSESSIONID=5A80785B002D8C37F73F798B75A090B4.47EF37A843F03A8253F26BC644; Path=/
< Location: http://www.thesite.org/
< Content-Length: 0
< Vary: Accept-Encoding
< Content-Type: text/html
<
* Connection #0 to host www.thesite.org left intact
* Issue another request to this URL: 'http://www.thesite.org/'
* Re-using existing connection! (#0) with host www.thesite.org
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET/HTTP/1.1
Host: www.thesite.org
Accept: */*
etc...
的問題是:
我在做什麼錯?如何使它工作?當然,我可以連接兩次並手動設置,但這不是我想要做的,這就是爲什麼我使用CURL
而不是file_get_contents()
。
你用什麼代碼來設置捲曲處理程序? –
已編輯的問題,上面的代碼。 –