php获取网页头部信息相关
php设置头部
<?php
header("HTTP/1.0 404 Not Found");
//header("HTTP/1.0 204 No Response");
?>
php通过内置函数获取头部信息
<?php
//$header = get_headers('http://xingdong365.com');
$header = get_headers('http://xingdong365.com',1);//会解析相应的信息并设定数组的键名
echo "<pre>";
print_r($header);
echo "</pre>";
?>
php通过curl获取头部信息
<?php
var_dump(get_header('http://xingdong365.com'));
function get_header($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY,true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_AUTOREFERER,true);
$header = curl_exec($ch);
return $header;
}
?>
已有 0 条评论