WordPress博客免插件php宝塔定时推送至百度收录

2023-3-8 921 3/8

在网站根目录下新建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;
?>

 

- THE END -

非特殊说明,本博所有文章均为博主原创。

共有 0 条评论