To use curl, you need to set up php.ini >< windows in the server, open php.ini, and find:
Extension=php_curl.dll
Removing the previous comment is both available.
The implementation code is as follows:
| The code is as follows |
Copy Code |
|
$curl = Curl_init ();
$url = ' http://www.111cn.net ';
curl_setopt ($curl, Curlopt_url, $url); Set URL
curl_setopt ($curl, Curlopt_header, 1); Get header
curl_setopt ($curl, curlopt_nobody,true); No, we just need head.
curl_setopt ($curl, Curlopt_returntransfer, 1); Save the data to a string, don't output it directly to the screen.
$data = curl_exec ($curl); Start Execution ~
Echo Curl_getinfo ($curl, Curlinfo_http_code); I know Httpstat code OH ~
Curl_close ($curl); When you finish, turn him off. |
or use the Get_headers function directly
Get_headers-gets the server to respond to all headers sent by an HTTP request
Example
| code is as follows |
copy code |
|
<?php
If (!function_exists (' get_headers ')) {
Function get_headers ($url, $format =0) {
$url =parse_url ($url);
$end = "\r\n\r\n";
$fp =fsockopen ($url [' Host '], (Empty ($url [' Port ']): $url [' Port ']), $errno, $errstr, 30);
if ($fp) {
$out = "get/http/1.1\r\n";
$out. = "Host:". $url [' Host ']. " \ r \ n ";
$out. = "connection:close\r\n\r\n";
$var = ';
Fwrite ($fp, $out);
while (!feof ($fp)) {
$var. =fgets ($FP, 1280);
if (Strpos ($var, $end)
break;
}
Fclose ($FP);
$var =preg_replace ("/\r\n\r\n.*\$/", "", $var);
$var =explode ("\ r \ n", $var);
if ($format) {
foreach ($var as $i) {
if (Preg_match/^ ([a-za-z-]+): + (. *) $/', $i, $parts)
$v [$parts [1]]= $parts [2];
}
return $v;
} else{
return $var;
}
}
}
Echo ' <pre> ';
Print_r (get_headers (' http://www.111cn.net ')); |