Typecho 添加“百度是否收录”判断的方法 PHP添加“百度是否收录”判断url百度收录的方法url优化修改版
编辑你的typecho主题的functions.php文件里新增下面函数:
例如:proyy.com/usr/themes/handsome/functions.php
/** * 提示文章百度是否收录 * */ function zh_baidu_record_submit() { $url='#39;.$_SERVER['REQUEST_URI']; $zh_arr = parse_url($url); $zh_url = '#39;.$zh_arr['path']; $url = $zh_url; #$url='#39;.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."<br>"; if(checkBaidu($url)==1) {echo "<a style=\"color:#fc6d26;\" rel =\"external nofollow\" title=\"邹洪博客百度已经收录啦!\" target=\"_blank\" href=\"#34;.$url."\">一一网络收录排名</a>"; } else { $urls = array( $url, ); $api = '#39;; $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=\"#34;>链接自动提交成功!</a>"; } else { echo "<a style=\"color:red;\" rel=\"external nofollow\" title=\"一一网文章链接自动提交至百度失败!\" target=\"_blank\" href=\"#34;>链接自动提交失败!</a>"; } } } function checkBaidu($url) { $url = '#39;. 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:
效果如下: