summaryrefslogtreecommitdiff
path: root/down/http.php
blob: 5e0351dd9601515d8f0f3892607f0a5b07dee711 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
function isUp($url, $ipv6 = false){

        $agent = "Just checking if you are up or not.";
        $ch=curl_init();

	if ( $ipv6 ){
		$url = "[".$url."]";
		curl_setopt($ch,CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
	}

        curl_setopt ($ch, CURLOPT_URL,$url );
        curl_setopt($ch, CURLOPT_USERAGENT, $agent);
        curl_setopt($ch, CURLOPT_NOBODY, true);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt ($ch,CURLOPT_VERBOSE,false);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5); 
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch,CURLOPT_SSLVERSION,3);
        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE);

        $page=curl_exec($ch);
        $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        if($httpcode>=200 && $httpcode<400 )
                return true;
        else 
                return false;
}

function sanitizeUrl($url){
	if ( ! preg_match("|^[a-zA-Z]+://|", $url) )
		$url = "http://" . $url;
	if ( preg_match("|^[a-zA-Z]+://.+\.[a-zA-Z]+(?<query>/.*)|", $url, $match) )
		$url = str_replace($match["query"], "", $url);

	return $url;
}