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

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

WBOY
WBOYOriginal
2016-06-13 13:45:241039browse

网页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;
} <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn