百度站长工具的链接提交方式之一,“主动推送(实时)”提交方式可以向百度搜索引擎实时推送网站的最新网址URL。当网站新增新的文章后,我们可以第一时间向百度引擎推送和提交链接,百度可能会马上收录。结合百度官方给的实例,下面是详细“php推送示例”教程:
你的网站要通过百度站长平台验证,才能使用下面的主动推送(实时);
获取代码
- 进入到百度站长平台--->链接提交--->数据提交方式--->自动提交--->主动推送(实时),在下方就可以看到你的推送接口,调用接口地址:

- 点击:推送示例--->php推送示例,复制下面的实例代码:如下图(当然)

修改代码
-
在本地新建一个"baidu.php"文件,打开后输入"";
-
将代码中$urls的值改为你要向百度引擎推送的链接URL,保存,我的代码如下:
<?php
$urls = array(
'https://www.zyglz.com/',
'https://www.zyglz.com/index.php/archive.html',
'https://www.zyglz.com/index.php/category/blog/',
'https://www.zyglz.com/index.php/category/tool/',
'https://www.zyglz.com/index.php/category/study/',
'https://www.zyglz.com/index.php/about.html',
'https://www.zyglz.com/index.php/links.html',
);
$api = 'http://data.zz.baidu.com/urls?site=你的网站域名&token=你的16位token值';
$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;
?>

- 将代码上传至你的服务区根目录(或者其它目录,记住路径即可)
主动推送
1.访问你的网站域名/baidu.php,即可,例如我的推送地址就为:https://www.zyglz.com/baidu.php。

- 成功后,反馈回来一串字符“{"remain":99562,"success":7}”,对照图即可得出对应数据的意义。

- 以后需要主动推送时,直接修改根目录“baidu.php”文件中$urls的值,访问刚刚的链接地址https://www.zyglz.com/baidu.php,即可完成。