新建PHP文件到网站任意目录后访问即可,也可以添加监控,每天自动提交收录,属于百度接口API提交下的PHP推送。
测试通过的环境:Linux+宝塔(Nginx1.16.1+Mysql5.6.47+PHP5.6)
如果运行出错,请检查是不是没有改数据库配置和百度接口,其次就是检查环境。
![图片[1]-修罗论坛使用PHP实现主动推送到百度 - KEKC博客-KEKC博客](http://www.kekc.cn/wp-content/uploads/2022/08/d2b5ca33bd153346.png)
PHP代码:
<?php//数据库信息$servername = "数据库地址";$username = "数据库用户名";$password = "数据库密码";$dbname = "数据库名";// 创建连接$conn = new mysqli($servername, $username, $password, $dbname);// 查看连接状态if ($conn->connect_error) {die("数据库连接失败: " . $conn->connect_error);}##sql语句(查询最大主题tid)$sql = "select * from `bbs_thread` order by tid DESC limit 1";$result = $conn->query($sql);if ($result->num_rows > 0) {// 输出数据while($row = $result->fetch_assoc()) {$zuihou= $row['tid'];}}$x=1;while($x<=$zuihou) {##sql语句$sql = "SELECT * FROM `bbs_thread` WHERE `tid` = $x";$result = $conn->query($sql);if ($result->num_rows > 0) {// 输出数据while($row = $result->fetch_assoc()) {// echo 'https://www.yinjiangbi.cn/?thread-'.$x.'.htm</br>';$shuzu=$x-1;//urls 数组循环赋值(全站主题赋值)$urls[$shuzu] ='https://yinjiangbi.cn/?thread-'.$x.'.htm';//网址拼接,改成自己的网址即可https://yinjiangbi.cn/?thread-1.htm}} else {// echo "主题不存在";}$x++;}//关闭数据库连接$conn->close();$api = 'http://data.zz.baidu.com/urls?site=https://yinjiangbi.cn&token=vdkjsnvjdsnvs';//百度接口(自行替换)$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);echo $result;//echo $urls[0];调试查看第一条?><?php //数据库信息 $servername = "数据库地址"; $username = "数据库用户名"; $password = "数据库密码"; $dbname = "数据库名"; // 创建连接 $conn = new mysqli($servername, $username, $password, $dbname); // 查看连接状态 if ($conn->connect_error) { die("数据库连接失败: " . $conn->connect_error); } ##sql语句(查询最大主题tid) $sql = "select * from `bbs_thread` order by tid DESC limit 1"; $result = $conn->query($sql); if ($result->num_rows > 0) { // 输出数据 while($row = $result->fetch_assoc()) { $zuihou= $row['tid']; } } $x=1; while($x<=$zuihou) { ##sql语句 $sql = "SELECT * FROM `bbs_thread` WHERE `tid` = $x"; $result = $conn->query($sql); if ($result->num_rows > 0) { // 输出数据 while($row = $result->fetch_assoc()) { // echo 'https://www.yinjiangbi.cn/?thread-'.$x.'.htm</br>'; $shuzu=$x-1; //urls 数组循环赋值(全站主题赋值) $urls[$shuzu] ='https://yinjiangbi.cn/?thread-'.$x.'.htm';//网址拼接,改成自己的网址即可https://yinjiangbi.cn/?thread-1.htm } } else { // echo "主题不存在"; } $x++; } //关闭数据库连接 $conn->close(); $api = 'http://data.zz.baidu.com/urls?site=https://yinjiangbi.cn&token=vdkjsnvjdsnvs';//百度接口(自行替换) $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); echo $result; //echo $urls[0];调试查看第一条 ?><?php //数据库信息 $servername = "数据库地址"; $username = "数据库用户名"; $password = "数据库密码"; $dbname = "数据库名"; // 创建连接 $conn = new mysqli($servername, $username, $password, $dbname); // 查看连接状态 if ($conn->connect_error) { die("数据库连接失败: " . $conn->connect_error); } ##sql语句(查询最大主题tid) $sql = "select * from `bbs_thread` order by tid DESC limit 1"; $result = $conn->query($sql); if ($result->num_rows > 0) { // 输出数据 while($row = $result->fetch_assoc()) { $zuihou= $row['tid']; } } $x=1; while($x<=$zuihou) { ##sql语句 $sql = "SELECT * FROM `bbs_thread` WHERE `tid` = $x"; $result = $conn->query($sql); if ($result->num_rows > 0) { // 输出数据 while($row = $result->fetch_assoc()) { // echo 'https://www.yinjiangbi.cn/?thread-'.$x.'.htm</br>'; $shuzu=$x-1; //urls 数组循环赋值(全站主题赋值) $urls[$shuzu] ='https://yinjiangbi.cn/?thread-'.$x.'.htm';//网址拼接,改成自己的网址即可https://yinjiangbi.cn/?thread-1.htm } } else { // echo "主题不存在"; } $x++; } //关闭数据库连接 $conn->close(); $api = 'http://data.zz.baidu.com/urls?site=https://yinjiangbi.cn&token=vdkjsnvjdsnvs';//百度接口(自行替换) $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); echo $result; //echo $urls[0];调试查看第一条 ?>
© 版权声明
THE END
暂无评论内容