Código PHP:
function isOnline($url) {
if (!$url_info = parse_url($url)) {
return false;
}
switch ($url_info['scheme']) {
case 'https':
$scheme = 'ssl://';
$port = 443;
break;
case 'http':
default:
$scheme = '';
$port = 80;
}
$data = "";
$fid = @fsockopen($scheme . $url_info['host'], $port, $errno, $errstr, 30);
if ($fid) {
fputs($fid, 'HEAD ' . (isset($url_info['path'])? $url_info['path']: '/') . (isset($url_info['query'])? '?' . $url_info['query']: '') . " HTTP/1.0\r\n" .
"Connection: close\r\n" .
'Host: ' . $url_info['host'] . "\r\n\r\n");
while (!feof($fid)) {
$data .= @fgets($fid, 128);
}
fclose($fid);
return !empty($data);
} else {
return false;
}
}