教程开始
1,在网站根目录新建一个文件夹,在文件夹新建一个 PHP 文件,
2,填写网站 sitemap.xml 地址和百度的推送接口,
3,把文件地址添加到宝塔定时任务,
4,选择访问 URL,自定义执行时间后,保存即可。
推送代码
<?php header('Content-Type:text/html;charset=utf-8');$xmldata =file_get_contents("https://自己网站/sitemap.xml");$xmlstring = simplexml_load_string($xmldata,'SimpleXMLElement',LIBXML_NOCDATA);$value_array = json_decode(json_encode($xmlstring),true);$url = [];for ($i =0;$i < count($value_array['url']);$i++){ echo $value_array['url'][$i]['loc']."<br/>"; $url[]= $value_array['url'][$i]['loc'];}$api ='百度站长的推送接口';$ch = curl_init();$options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode("\n",$url), CURLOPT_HTTPHEADER => array('Content-Type:text/plain'),);curl_setopt_array($ch, $options);$result =curl_exec($ch);echo $result;?>
返回下面代码就说明推送成功
成功会返回{"remain": 今日剩余数,"success": 推送成功数} 的。
评论
后面还有条评论,点击查看 >>