2011-11-14 6 views
0

file_get_contents가 URL에 빈 문자열을 돌려줍니다. 이 모든 것을 확인하고가 문자PHP GET 요청이 비어

string(143) "HTTP/1.1 200 OK 
X-Powered-By: PHP/5.3.8 
Content-type: text/html 
Content-Length: 0 
Date: Mon, 14 Nov 2011 20:27:01 GMT 
Server: lighttpd 

" 
string(0) "" 

내가 삭제를 "http://thepiratebay.org/search"URL을 변경하는 경우 : 도

$ch = curl_init(); 
$cookieFile = 'cookies.txt'; 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); 
curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
curl_setopt($ch, CURLOPT_TIMEOUT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'); 

$url = 'http://thepiratebay.org/search/a'; 
curl_setopt($ch, CURLOPT_URL,$url); 

$html = curl_exec ($ch); 
var_dump($html); 
$html = file_get_contents($url); 
var_dump($html); 

curl_close ($ch); unset($ch); 

출력은 heres는 내 코드, 컬 시도 나는 좋은 반응을 얻는다.

어떤 아이디어가 있습니까?

답변

2

CURLOPT_TIMEOUT을 사용하여 사용자 에이전트 문자열을 설정하려고합니다. CURLOPT_USERAGENT을 사용해보세요. 문제가 해결 될 것입니다. file_get_contents을 사용하려면 stream_context_create 또는 ini_set을 사용하여 같은 시간을 할 수 있습니다.

세 가지 기술에 대한 예제는 http://www.seopher.com/articles/how_to_change_your_php_user_agent_to_avoid_being_blocked_when_using_curl에서 확인할 수 있습니다.

+0

lolz, 어리석은 실수, ty, 그것이 CURLOPT_USERAGENT였습니다. 파이썬으로 작성했습니다. :) – Legion

0

file_get_contents은 설치시 URL을 열지 못할 수 있습니다. fopen_wrappers을 참조하십시오. 또는 thepiratebay.org가 file_get_contents 통화의 사용자 에이전트 때문에 사용자를 차단할 수 있습니다. context을 전달하세요. 또는 curl처럼 자신의 file_get_contents 통화에서 쿠키를 보내지 않았으므로 아무 것도 반환하지 않을 수도 있습니다. 요점은 URL이 같더라도 요청이 다릅니다.