No more nonsense. Directly on the code
Core code:
/**
* Get HTTP status of remote URL
* *
@version 0.0.1
* @Author CHENJL * * *
@param string $url remote URL
* @ param string $data ture[return HTTP status array] | false[return status value]
*
* @return mixed
/function Getheaders ($ URL, $data =false) {
$_headers = get_headers ($url, 1);
if (! $data) {return $_headers;}
$curl = Curl_init ();
curl_setopt ($curl, Curlopt_url, $url);//get Content URL
curl_setopt ($curl, curlopt_header,1); Get HTTP header information
curl_ Setopt ($curl, curlopt_nobody,1);//Do not return the body information of HTML
curl_setopt ($curl, curlopt_returntransfer,1);//return data stream without direct output
curl_setopt ($curl, curlopt_timeout,30),//timeout length, Unit seconds
curl_exec ($curl);
$rtn = Curl_getinfo ($curl, curlinfo_http_code);
Curl_close ($curl);
return $rtn;
}
The above code, by the wind has been two ways to obtain a consolidation of access, to facilitate the different access to the HTTP status scenario needs;
return Result:
# Invoke Case 1:getheaders (' http://www.jb51.net\/\ ', true);
# return Result: 200//Direct return HTTP status Code
# call Case 2:getheaders (' http://www.jb51.net/', false);
# return Result:/
*
Array {
[0]=>
string ' http/1.1 ok '
[' Server ']=>
string (5) ' Nginx "
[Date"]=>
string "Mon, 2016 06:21:35 GMT"
[content-type "]=>
string (9)" Text/html "
[content-length"]=>
string (5) "26898"
[last-modified "]=>
string" Mon, June 2016 06:16:00 GMT "
[Connection"]=>
string (5) "Close"
["Vary"]=>
string (15)] Accept-encoding "
[" ETag "]=>
string" "5779ff20-6912"
["Accept-ranges"]=>
string (5 ) "bytes"
}
* *