检查URL地址

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');
    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值