Modifiqué la respuesta de Adam Backstrom e implementé la sugerencia de chiborg. (Descargar solo HEAD). Tiene una cosa más: comprobará si la redirección está en una página del mismo servidor o está fuera. Ejemplo: terra.com.br redirige a terra.com.br/portal. PHP lo considerará como redirigir, y es correcto. Pero solo quería enumerar esa URL que redirecciona a otra URL. Mi inglés no es bueno, entonces, si alguien encuentra algo realmente difícil de entender y puede editar esto, de nada.
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;
}
}
}
}
}
}
redirigidas cómo? Llamado de qué cliente? ¿Cuándo inicias sesión o cuando no estás conectado? ¿Para qué? ¿El guión tendrá que manejar las cookies de sesión y otras cosas complicadas? –
Defina "URL redirigida" por favor. –
Ver [¿Cómo puedo determinar si una URL redirige en PHP?] (Http://stackoverflow.com/questions/427203/how-can-i-determine-if-a-url-redirects-in-php/481377# 481377) –