나는 Adam Backstrom 대답을 수정하고 chiborg 제안을 구현했습니다. (HEAD 만 다운로드). 한 가지 더 있습니다 : 리디렉션이 동일한 서버의 페이지에 있는지 또는 없는지 확인합니다. 예 : terra.com.br은 terra.com.br/portal로 리디렉션됩니다. PHP는 리다이렉트 (redirect)와 같은 것으로 고려할 것이고, 올바른 것입니다. 하지만 난 단지 다른 URL로 리디렉션하는 URL을 나열하고 싶었어요. 내 영어가 좋지 않습니다. 누군가 이해하기 어려운 것을 발견하고이를 편집 할 수 있다면 환영합니다.(302) 이후
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
가 이동을 의미 컬 호출을 따라 어떤 이동 된 URL의 수익률을 반환 할 수 있습니다 :
function RedirectURL() {
$urls = array('http://www.terra.com.br/','http://www.areiaebrita.com.br/');
foreach ($urls as $url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// chiborg suggestion
curl_setopt($ch, CURLOPT_NOBODY, true);
// ================================
// READ URL
// ================================
curl_setopt($ch, CURLOPT_URL, $url);
$out = curl_exec($ch);
// line endings is the wonkiest piece of this whole thing
$out = str_replace("\r", "", $out);
echo $out;
$headers = explode("\n", $out);
foreach($headers as $header) {
if(substr(strtolower($header), 0, 9) == "location:") {
// read URL to check if redirect to somepage on the server or another one.
// terra.com.br redirect to terra.com.br/portal. it is valid.
// but areiaebrita.com.br redirect to bwnet.com.br, and this is invalid.
// what we want is to check if the address continues being terra.com.br or changes. if changes, prints on page.
// if contains http, we will check if changes url or not.
// some servers, to redirect to a folder available on it, redirect only citting the folder. Example: net11.com.br redirect only to /heiden
// only execute if have http on location
if (strpos(strtolower($header), "http") !== false) {
$address = explode("/", $header);
print_r($address);
// $address['0'] = http
// $address['1'] =
// $address['2'] = www.terra.com.br
// $address['3'] = portal
echo "url (address from array) = " . $url . "<br>";
echo "address[2] = " . $address['2'] . "<br><br>";
// url: terra.com.br
// address['2'] = www.terra.com.br
// check if string terra.com.br is still available in www.terra.com.br. It indicates that server did not redirect to some page away from here.
if(strpos(strtolower($address['2']), strtolower($url)) !== false) {
echo "URL NOT REDIRECT";
} else {
// not the same. (areiaebrita)
echo "SORRY, URL REDIRECT WAS FOUND: " . $url;
}
}
}
}
}
}
방법 리디렉션을? 어떤 고객에게 전화 했습니까? 로그인했을 때 또는 로그인하지 않았을 때? 무엇 때문에? 스크립트가 세션 쿠키 및 기타 복잡한 작업을 처리해야합니까? –
"리디렉션 된 URL"을 지정하십시오. –
[PHP에서 URL 리디렉션을 어떻게 확인할 수 있습니까?] (http://stackoverflow.com/questions/427203/how-can-i-determine-if-a-url-redirects-in-php/481377#) 481377) –