登录 注册 VIP特权 提交收录
Search Engine Optimization,不撸代码不修BUG

域名出售:ioee.cn(爱),联系QQ:49613651
应广大客户要求,本站价格上调,别问为什么,没理由~!

主页 » 教程 » 正文

为typecho文章页添加百度收录检测 2.0

post.php中添加

    <script> 
            function baidu_check(){ 
                var url= window.location.href 
                $.getJSON("https://www.xiaobai666.top/usr/theme/Cuteen/baidu.php?domain="+url,function(result){ //调用api 
                    if (result.code == 200) { 
                        $('#baidu_icon').removeClass('glyphicon-refresh'); 
                        $('#baidu_icon').addClass('glyphicon-ok-circle'); 
                        $('#baidu_result').text('百度已收录'); 
                    }else if(result.code == 403){ 
                        $('#baidu_icon').removeClass('glyphicon-refresh'); 
                        $('#baidu_icon').addClass('glyphicon-info-sign'); 
                        /*$('#baidu_result').text('百度未收录');*/ 
                        $('#baidu_result').html('<a style="color:red;" rel="external nofollow" title="点击提交收录!" target="_bl
    ank" href="https://ziyuan.baidu.com/linksubmit/url?sitename='+url+'">百度未收录</a>'); 
     
                    }else{ 
                        $('#baidu_icon').removeClass('glyphicon-refresh'); 
                        $('#baidu_icon').addClass('glyphicon-remove-circle'); 
                    

并在合适的位置添加

    <!--百度收录--> 
    <span class="item"><i class="iconfont icon-liulanqi"></i></span><span class="meta-value" id="baidu_result">加载中</span> 
    

api 代码

    <?php
    /**
     * Baidu
     * @editer: Weifeng
     * @link: 
     * @version: 1.0
     */
    
    error_reporting(0);
    header("Access-Control-Allow-Origin:*");
    header('Content-type: application/json');
    
    $domain = @$_GET['domain'];
    if(!isset($domain) || empty($domain) || $domain==''){
        $data = array(
            "code" => false,
            "msg" => "未传入请求参数!"
        );
        echo json_encode($data,JSON_UNESCAPED_UNICODE);
        exit;
    }
    if(substr($domain, -1) == '/'){
        $domain = substr($domain,0,strlen($domain)-1);
    }
    
    $data = checkBaidu($domain);
    echo json_encode($data,JSON_UNESCAPED_UNICODE);
    
    function checkBaidu($url){
        $header = array(
            "Host:www.baidu.com",
            "Content-Type:application/x-www-form-urlencoded",//post请求
            "Connection: keep-alive",
            "Referer:https://www.baidu.com",
            "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Safari/537.36"
        );
        $url = 'https://www.baidu.com/s?ie=UTF-8&wd='.urlencode($url).'&usm=3&rsv_idx=2&rsv_page=1';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);
        curl_close($ch);
        if(strpos($output, '没有找到') || strpos($output, '很抱歉')){
            $data = array(
                "code" => 403,
                "msg" => "该域名暂时未被百度收录!"
            );
        }else{
            $number = GetBetween($output,'<span class="nums_text">百度为您找到相关结果约','个</span>');
            if(empty($number) || $number == 0){
                $number = GetBetween($output,'<b>找到相关结果数约','个</b></p>');
                if(empty($number) || $number == 0){
                    $data = array(
                        "code" => false,
                        "msg" => "获取百度收录失败!"
                    );
                    return $data;
                }
            }
            $data = array(
                "code" => 200,
                "msg" => "该域名已被百度收录!",
                "number" => str_replace(',','',$number)
            );
        }
        return $data;
    }
    
    function GetBetween($content,$start,$end){
        $r = explode($start, $content);
        if (isset($r[1])){
            $r = explode($end, $r[1]);
            return $r[0];
        }
    }
    ?>
    

在pjax中添加

    <!--百度收录-->
    if((typeof baidu_check) !== "undefined"){
    baidu_check();
    }


您的大名:
万水千山总是情,给个打赏行不行。 打赏

标签: 添加百度收录
! 如链接失效请在下方留言。本站所发布的全部内容源于互联网搬运,仅限于小范围内传播学习和文献参考,请在下载后24小时内删除,如果有侵权之处请第一时间联系我们删除。敬请谅解! E-mail:49613651@qq.com
原创文章,作者:一宇A1xt,如若转载,请注明出处:http://www.a1xt.com/archives/655.html

相关推荐

给自己Typecho的文章添加是否被百度收录1.0

在目录 /functions.php 文件 尾部增加function baidu_record() { $url='http://'....


猜你喜欢

将TeConnect的社会化登录数据无缝迁移到TePass中

在post.php中添加 <script> function baidu_check(){...


上一篇
下一篇

发表评论