1

我在家里托管自己的服务器,但我使用 000webhost 作为获取域并使用 PHP 脚本将其指向我的服务器的一种方式(我的 ISP 为我的“安全”阻止了端口 80)我想知道我是否可以使用 PHP 脚本并让它 ping 我的网络服务器,如果它关闭重定向到另一个网站/文件,让我的少数用户知道它已经关闭。如果 PHP 不能做到这一点,那么你会建议什么?

4

2 回答 2

0

如果您想 ping 您的站点,请使用 CURL,然后重定向。

function checkSite($url, $timeout = 80) {  
        $curl = curl_init($url);  
        curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);  
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);  
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);  

        $data = curl_exec($curl);  
        $response = curl_getinfo($curl, CURLINFO_HTTP_CODE);  
        curl_close($curl);  

    /**
     * Check if error ranges between 200 and 300
     */
    return ($response >= 200 && $response < 300) ? true : false;
}

//Check the site
if (checkSite("http://yourdomain.com")) {
    //YOUR REDIRECT HERE
}
于 2013-08-01T01:07:31.043 回答
0
get_headers ( string $url [, int $format = 0 ] )

http://php.net/manual/en/function.get-headers.php

于 2013-08-01T00:23:37.803 回答