2016-10-23 17 views
0

CURL 및 리디렉션CURL 및 리디렉션

안녕.

일부 사이트를 확인하는 데 CURL을 사용하고 있습니다. 일부 리디렉션에 문제가 있습니다. 매번이 아니라 단지 몇 가지 경우입니다.

이 경우 302 코드가 있지만 리디렉션 URL은 원래 URL과 같습니다. CURL 변수의

덤프 :

array(23) { 
["url"]=> string(33) "http://www.apostasurpresa.gov.br/" 
["content_type"]=> string(24) "text/html; charset=UTF-8" 
["http_code"]=> int(302) 
["header_size"]=> int(180) 
["request_size"]=> int(92) 
["filetime"]=> int(-1) 
["ssl_verify_result"]=> int(0) 
["redirect_count"]=> int(0) 
["total_time"]=> float(0.037685) 
["namelookup_time"]=> float(0.000171) 
["connect_time"]=> float(0.018808) 
["pretransfer_time"]=> float(0.01882) 
["size_upload"]=> float(0) 
["size_download"]=> float(0) 
["speed_download"]=> float(0) 
["speed_upload"]=> float(0) 
["download_content_length"]=> float(0) 
["upload_content_length"]=> float(0) 
["starttransfer_time"]=> float(0.037521) 
["redirect_time"]=> float(0) 
["redirect_url"]=> string(33) "http://www.apostasurpresa.gov.br/" 
["primary_ip"]=> string(15) "200.201.166.106" 
["certinfo"]=> array(0) { } } 

컬 페이지 :

$ch = curl_init();  
curl_setopt($ch, CURLOPT_AUTOREFERER, 1); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,60); 
curl_setopt($ch, CURLOPT_COOKIESESSION , 1); 
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt'); 
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt'); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST ,'GET'); 
//  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
//  curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_HEADER, 1); // true 
curl_setopt($ch, CURLOPT_MAXREDIRS, 10); 
curl_setopt($ch, CURLOPT_POST, 0); 
curl_setopt($ch, CURLOPT_POSTREDIR, 6);// 3 => 6 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // false 
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0"); 
$txt_pagina = curl_exec($ch); 
$info=curl_getinfo($ch); 
curl_close($ch); 

감사

+0

나는 curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 0)을 시도했다; 과 동일한 결과가있는 curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1). – RSLyra

+0

브라우저에서 페이지를 방문하면 어떻게됩니까? 서버가 사용자 에이전트에 만족스럽지 않고 따라서 루프로 다시 리디렉션 될 수 있다고 생각합니까? "실제"브라우저의 사용자 에이전트 문자열을 사용해보십시오 ... – ivanivan

+0

http://loterias.caixa.gov.br/wps/portal/loterias/로 리디렉션하십시오. – RSLyra

답변

0

OK, 코멘트 후 답변 :

와 다음 내가 확인이 wget을 사용하면 실제로 포털 페이지 URL에 착륙하기 전에 여러 위치로 리디렉션됩니다. u는 위에 제공했다.

원래의 URL은 302를 던지고, 301, 그 다음 301을 참조합니다. 그런 다음 리디렉션되는 URL은 많은 자바 스크립트를 제공하고 자바 스크립트는 리디렉션을 수행합니다. 이 ... 자바 스크립트 리디렉션

그래서 ... 솔루션을 구문 분석하지 않기 때문에

그래서 코드가 작동하지 않습니다. 다중 리디렉션을 처리하는 대신 포털 페이지를 가리 키지 않는 이유는 무엇입니까? URL이 /로 끝나지 않으면 BTW URL이 http://loterias.caixa.gov.br/wps/portal/loterias/을 URL로 사용하여 리디렉션됩니다.

+0

이것은 해결책이며 작동합니다. 하지만 ... 정부 등록 도메인의 공식 목록이 있습니다. 이것이 내 별의 핵심입니다. www.apostasurpresa.gov.br에서 loterias.caixa.gov.br/wps/portal/loterias로 변경하고 내일 리디렉션을 변경하면 잘못된 도메인을 확인합니다. 내가 확인하고있는 한 가지는 동일한 페이지로 이동하는 리디렉션입니다. 하지만 문제에 대해 자세히 알려 주셔서 감사합니다. – RSLyra