新建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;
?>


声明:邓先生的资源库|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - 新建php文件实现百度自动推送


风吹雪不浮