DEDE百度推送代码

PHP 2019-10-20 21:27:24 评论

PHP版本

$url = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
//百度是否收录
function Baidu($url) {
    $url = 'http://www.baidu.com/s?wd=' . urlencode($url);
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $content= curl_exec($curl);
    curl_close($curl);
    if (!strpos($content, '没有找到')) { //没有找到说明已被百度收录
        return false;
    } else {
        return true;
    }
}

//引入测验百度没有收录并加载代码的函数
function baidu_php_push($url){
    $wz = 'https://'.$_SERVER['HTTP_HOST'];
    $token = "百度的token";
    $check = Baidu($url);
    if($check==false){
    $urls[]=$url;
    $api = 'http://data.zz.baidu.com/update?site='.$wz.'&token='.$token;
    $ch = curl_init();
    $options =  array(
    CURLOPT_URL => $api,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => implode("
", $urls),
    CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
	echo $result;

  }else{

    $urls[]=$url;
    $api = 'http://data.zz.baidu.com/urls?site='.$wz.'&token='.$token.'&type=mip';
    $ch = curl_init();
    $options =  array(
    CURLOPT_URL => $api,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => implode("
", $urls),
    CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);

    $urls2[]=$url;
    $api = 'http://data.zz.baidu.com/urls?site='.$wz.'&token='.$token;
    $ch = curl_init();
    $options =  array(
    CURLOPT_URL => $api,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => implode("
", $urls2),
    CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
}
}
echo baidu_php_push($url);
上一篇:没有了
下一篇:PHP小偷常用代码

评论

说点什么吧
  • 全部评论(0
    还没有评论,快来抢沙发吧!