PHP百度收录数量API查询源码本地化-拾艺肆

PHP百度收录数量API查询源码本地化

前言

 

现在做站会有些站长把收录数量显示在网站底部,一来自己可以知道网站收录数量多少,二来申请友链的伙伴们也知道你网站有多少收录,不过大多数人都是用别人的API接口来实现,假如别人的API接口失效了,自己网站就多了个404的JS文件,这样会导致网站打开速度慢了一点点!这里直接把接口源码分享了!

 

PHP百度收录数量API查询源码本地化,image.png,百度收录,百度域名,网站源码,源码分享,百度,网站收录,域名,api接口,第1张

 

在网站新建一个php文件,把下面的代码复制进去

 

API接口的源码,查询实例:你网站域名/文件.php?domain=查询域名

 

演示:https://www.maowuo.cn/baidu.php?domain=wenytao.com

<?php
/*
Plugin Name: XY-百度收录量
Description: XY-根据域名返回百度收录量
*/
$domain = (isset($_GET['domain']))?$_GET['domain']:$_POST['domain'];
if(empty($domain))  echo '查询域名不能为空';
$count = baiduSL ($domain);
if(!isset($count))  showjson(array('code'=>200502,'msg'=>'查询失败,请重试!'));
if(!$count)  $count = 0;
$result=array(
   'code'=>1,
   'domain'=>$domain,
   'data'=>$count
);
print_r(json_encode($result));
unset($domain,$result,$ch);
function baiduSL ($domain) {
    $baidu='https://www.baidu.com/s?ie=utf-8&tn=baidu&wd=site%3A'.$domain;
    $bdsite=BD_curl($baidu);
    $bdsite = str_replace(array("\r\n", "\r", "\n", '    '), '', $bdsite);
    if (!$count) preg_match('/找到相关结果数约(.*?)个/i',$bdsite,$count);
    $baiduSL=strip_tags($count[1]);
    unset($count);
    return $baiduSL;
}
function BD_curl($url){
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1");
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   $ret = curl_exec($ch);
   curl_close($ch);
   return $ret;
}
?>

 

请登录后发表评论

    请登录后查看回复内容

 

昼夜

客服

点击联系站长 点击联系站长

在线时间
12:00 - 22:00

关注微信公众号

关注微信公众号
交流QQ群

244075032

站长邮箱 apeng123@88.com