set_time_limit(0);
function check_url($url) {
// Break the URL down into its parts:
$url_pieces = parse_url($url);
// Set the $path and $port:
$path = (isset($url_pieces['path'])) ? $url_pieces['path'] : '/';
$port = (isset($url_pieces['port'])) ? $url_pieces['port'] : 80;
// Connect using fsockopen():
if ($fp = fsockopen($url_pieces['host'], $port, $errno, $errstr, 30)) {
// Send some data:
$send = "HEAD $path HTTP/1.1\r\n";
$send .= "HOST: {$url_pieces['host']}\r\n";
$send .= "CONNECTION: Close\r\n\r\n";
fwrite($fp, $send);
// Read the response:
$data = fgets($fp, 128);
// Close the connection:
fclose($fp);
// Return the response code:
list($response, $code) = explode(' ', $data);
if ($code == 200) {
return array($code, 'good');
} else {
return array($code, 'bad');
}
} else { // No connection, return the error message:
return array($errstr, 'bad');
}
}
检查URL地址
最新推荐文章于 2020-12-06 12:42:36 发布