当前位置:Gxlcms > PHP教程 > 网页Http返回状态值查询(404,200,301,302,500)这种怎么实现呢

网页Http返回状态值查询(404,200,301,302,500)这种怎么实现呢

时间:2021-07-01 10:21:17 帮助过:8人阅读

网页Http返回状态值查询(404,200,301,302,500)这种如何实现呢?
例如像这个网站的。
可以查询网站的返回状态

http://www.mjjer.com/gethttpheader.php

------解决方案--------------------
curl为例:
PHP code

function curl_file_get_contents($durl){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $durl);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $r = curl_exec($ch);
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
    return $http_code;
}                     

人气教程排行