您的位置:首页 > 其它

检查URL地址

2016-01-06 10:26 381 查看
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');
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: