note 75388 added to function.fsockopen
| From: | AlexanderWegener at osu1 dot php dot net | Date: | Sat, 26 May 2007 14:29:17 +0000 |
| Subject: | note 75388 added to function.fsockopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-126937@lists.php.net to get a copy of this message | ||
To check if a Url is Online (with http and https)
Using @fgets to hide Warning when using SSL
(Bug: "Warning: function.fgets SSL: fatal protocol error", http://bugs.php.net/bug.php?id=23220)
<?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;
}
}
?>
----
Server IP: 217.13.201.10
Probable Submitter: 134.155.22.233
----
Manual Page -- http://www.php.net/manual/en/function.fsockopen.php
Edit -- https://master.php.net/note/edit/75388
Del: integrated -- https://master.php.net/note/delete/75388/integrated
Del: useless -- https://master.php.net/note/delete/75388/useless
Del: bad code -- https://master.php.net/note/delete/75388/bad+code
Del: spam -- https://master.php.net/note/delete/75388/spam
Del: non-english -- https://master.php.net/note/delete/75388/non-english
Del: in docs -- https://master.php.net/note/delete/75388/in+docs
Del: other reasons-- https://master.php.net/note/delete/75388
Reject -- https://master.php.net/note/reject/75388
Search -- https://master.php.net/manage/user-notes.php