利用360的site功能查询网站的备案号

<?php
header("Content-type:text/html;charset=utf-8");
function get_curl($url, $post = 0, $referer = 0, $cookie = 0, $header = 0, $ua = 0, $nobaody = 0) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $httpheader[] = "Accept:application/json";
    $httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
    $httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
    $httpheader[] = "Connection:close";
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
    if ($post) {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }
    if ($header) {
        curl_setopt($ch, CURLOPT_HEADER, true);
    }
    if ($cookie) {
        curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    }
    if ($referer) {
        if ($referer == 1) {
            curl_setopt($ch, CURLOPT_REFERER, 1);
        } else {
            curl_setopt($ch, CURLOPT_REFERER, $referer);
        }
    }
    if ($ua) {
        curl_setopt($ch, CURLOPT_USERAGENT, $ua);
    } else {
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; U; Android 4.0.4; es-mx; HTC_One_X Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0");
    }
    if ($nobaody) {
        curl_setopt($ch, CURLOPT_NOBODY, 1);
    }
    curl_setopt($ch, CURLOPT_ENCODING, "gzip");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $ret = curl_exec($ch);
    curl_close($ch);
    return $ret;
}

@$url = $_POST['url']?$_POST['url']:$_GET['url'];

$data=file_get_contents("https://www.so.com/s?ie=utf-8&src=360chrome_toolbar_search&q=site%3a".$url);

preg_match('|<p class="info">备案号:(.*?)<\\/p>|', $data, $country);
//$country = $country[1];

        if (!$url) 
                     {
            echo '没有输入网址,请重试!';
  
                       }
        else{
            if(empty($country[1])){
                //echo '{"status":0,"msg":"没有备案号"}';
                echo '没有备案号';
            }
            else{ 
            //$data = '{"status":1,"msg":"'.$country.'"}';
            echo $country[1];
            }
                }
?>

演示:https://api.biuer.cn/beian/?url=baidu.com url等于你查询的网址,如遇特殊情况,已备案域名没显示备案号,请自行解决

代码为原创,转载请注明!

最后修改:2020 年 08 月 18 日
如果觉得我的文章对你有用,请随意赞赏