2011-10-13 6 views
0

가능한 복제를 최종 URL을 찾는 방법 : 나는 URL의 내용을 얻을 수 file_get_contents('http://someurl.com/1893849')을 사용하고
How to get the real URL after file_get_contents if redirection happens?리디렉션에

하지만 URL 리디렉션됩니다. 예를 들어 /1893849/some-url-path으로 끝납니다. 파일 내용을 얻는 것 외에도 끝 경로를 알 수있는 방법이 있습니까?

+0

가능한 재 게시의 ADRES을 알고 필요한 경우 : http://stackoverflow.com/q/4323985/971312 –

+0

'file_get_contents'를 통해서가 아닙니다. 'cURL' 라이브러리를 살펴보고 특히'curl_setopt()'- CURLOPT_FOLLOWLOCATION'을 가지고 놀아보십시오. –

답변

1

Use curl example :

curl_setopt($init, CURLOPT_FOLLOWLOCATION, 1); 

이의 redirec

curl_setopt($init, CURLOPT_HEADER, 1); 
curl_setopt($init, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt($init, CURLOPT_HTTPHEADER, array('Expect:')); 

if (strstr($content, 'Moved Temporarily') or 
strstr($content, 'Moved Permanently') or strstr($content, '302 Found') ) : 

if (preg_match('@Location: (.*?)\[email protected]', $content, $red)) : 

print_r($red); 

endif; 
+0

영어 문자열'Moved Temporarily' 또는'Moved Permanently' 또는'302 Found'를 찾는 것은 좋지 않습니다. 상태 코드 (그리고 상태 코드 만)에 대한 출력의 맨 처음 줄을 확인하는 것이 훨씬 더 강력 할 것입니다. – sarnold

관련 문제