Typecho 添加“百度是否收录”判断的方法 PHP添加“百度是否收录”判断url百度收录的方法url优化修改版

编辑你的typecho主题的functions.php文件里新增下面函数:

例如:proyy.com/usr/themes/handsome/functions.php

/**
* 提示文章百度是否收录
*
*/
function zh_baidu_record_submit() {
$url='https://www.proyy.com'.$_SERVER['REQUEST_URI'];
$zh_arr = parse_url($url);
$zh_url = 'https://www.proyy.com'.$zh_arr['path'];
$url = $zh_url;
#$url='https://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."<br>";
if(checkBaidu($url)==1)
{echo "<a style=\"color:#fc6d26;\" rel=\"external nofollow\" title=\"邹洪博客百度已经收录啦!\" target=\"_blank\" href=\"https://www.baidu.com/s?wd=".$url."\">一一网络收录排名</a>";
}
else
{
    $urls = array(
    $url,
);
$api = 'http://data.zz.baidu.com/urls?site=https://www.proyy.com&token=1u0gwwVnPSUWFKyo';
$ch = curl_init();
$options =  array(
    CURLOPT_URL => $api,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => implode("\n", $urls),
    CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);

if (strpos($result,'success') && strpos($result,':1')) { //找到说明已被百度收录
echo "<a style=\"color:red;\" rel=\"external nofollow\" title=\"一一网文章链接自动提交至百度成功!\" target=\"_blank\" href=\"http://zhanzhang.baidu.com/sitesubmit/index?sitename=$url\">链接自动提交成功!</a>";
} else {
echo "<a style=\"color:red;\" rel=\"external nofollow\" title=\"一一网文章链接自动提交至百度失败!\" target=\"_blank\" href=\"http://zhanzhang.baidu.com/sitesubmit/index?sitename=$url\">链接自动提交失败!</a>";
}
}
}
function checkBaidu($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);
$rs = curl_exec($curl);
curl_close($curl);
if (!strpos($rs, '没有找到')) { //没有找到说明已被百度收录
return 1;
} else {
return -1;
}
} 

主题post或者page页面中使用下面的代码进行调用:

<span class="baidu-record"><?php echo zh_baidu_record_submit() ?></span>

以上为一一网百度收录url自动查询收录提交收录源码优化修改版,css如有需要请copy view-source:https://www.proyy.com/3757.html

转载请保留一一网版权

Last modification:December 10th, 2019 at 04:13 pm
如果觉得我的文章对你有用,请随意赞赏