直接上代碼:curl
function get_header( $url , $host_ip = null){
$ch = curl_init(); //curl初始化
if(!is_null($host_ip)){//須要綁定ipurl
$urldata = parse_url($url);ip
//url有參數get
if (!empty($urldata['query']))
$urldata['path'] .= "?".$urldata['query'];域名
//域名設置
$headers = array("Host: ".$urldata['host']);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);it
//須要綁定的ip
$url = $urldata['scheme']."://".$host_ip.$urldata['path'];
}
curl_setopt($ch, CURLOPT_URL, $url);//獲取的地址io
curl_setopt ($ch, CURLOPT_HEADER, 1);//獲取頭信息
curl_setopt($ch, CURLOPT_NOBODY,1);//body信息不獲取
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec ($ch);function
//var_dump($result);
curl_close ($ch);//關閉curl
return $result;top
}
query