Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boas
Peguei um código para verificar se o site (url) está activo.
Mas por vezes o resultado é errado, quando o cabeçalho é em http 1.0(falso morto) se for 1.1 funciona bem.
uma ajudinha ai?
function page_exists($url){
$parts=parse_url($url);
if(!$parts) return false; /* the URL was seriously wrong */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
/* set the user agent - might help, doesn't hurt */
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
/* try to follow redirects */
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_ENCODING, "");
/* timeout after the specified number of seconds. assuming that this script runs
on a server, 20 seconds should be plenty of time to verify a valid URL. */
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
/* don't download the page, just the header (much faster in this case) */
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_HEADER, true);
/* handle HTTPS links */
if($parts['scheme']=='https'){
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
curl_exec ($ch);
$intReturnCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
if ($intReturnCode != 200 && $intReturnCode != 301 && $intReturnCode != 302 && $intReturnCode != 304) {
return '<font color="red"> -Morto</font>';
}
else {
return '<font color="green"> -OK</font>';
}
}
$query = mysql_query("SELECT * FROM sites");
while($row = mysql_fetch_assoc($query)){
<td><a href="http://'.$row['url'].'" target="_blank">'.$row['url'].page_exists($row['url']).'</a></td>
}Carregando comentários...