邓先生的资源库

新建php文件实现百度自动推送

一般大家推送都是使用插件推送呢还是随缘呢 这个我就不太清楚大家的方式了

在网站根目录下新建php文件,文件名随意,例baiduts.php,填写网站sitemap.xml地址和百度站长的推送接口,把自定义的文件地址添加在宝塔定时任务,选择访问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_POSTFIELDS => implode("\n",$url),
CURLOPT_HTTPHEADER => array('Content-Type:text/plain'),
);
curl_setopt_array($ch, $options);
$result =curl_exec($ch);
echo $result;
?>


本原创文章未经允许不得转载 | 当前页面:邓先生的资源库 » 新建php文件实现百度自动推送

评论


|  Sitemap  |  App  |  Status  |  Stats  |  E-Mail |

已续  ,感谢有你
陕ICP备2022002237号

  开往-友链接力  飞翔