PHP: Check availability of a site
- function checkUrl($url) {
- $agent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERAGENT, $agent);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_VERBOSE, false);
- curl_setopt($ch, CURLOPT_TIMEOUT, 5);
- $page = curl_exec($ch);
- $resp = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close($ch);
- if (($resp >= 200) && ($resp < 310))
- return true;
- else
- return false;
- }
- if (checkUrl("http://example"))
- echo "Website is available";
- else
- echo "Website is not available<br>";
Комментариев нет:
Отправить комментарий