PHP批量向百度主动推送URL加快收录的示例代码

后端开发   发布日期:2023年05月19日   浏览次数:450

本篇内容主要分享PHP代码方式,实现批量向百度主动推送URL地址,从而加快百度收录的示例代码。思路就是动态生成URL数组,通过array和array_push生成地址的数组,再一次性提交至百度。

  1. if ($action=="baidu_everyone"){
  2. $functionstr = array();
  3. $sql_search_pro="select id from mdaima_it where pass='1' order by id desc limit 30";
  4. $result_pro=$mysqli->query($sql_search_pro);
  5. while ($rs_pro=$result_pro->fetch_assoc()){
  6. array_push($functionstr,"https://".$var_domain."/it/".$rs_pro["id"].".html");
  7. }
  8. $sql_search_pro="select id from mdaima_jingyan where pass='1' order by id desc limit 30";
  9. $result_pro=$mysqli->query($sql_search_pro);
  10. while ($rs_pro=$result_pro->fetch_assoc()){
  11. array_push($functionstr,"https://".$var_domain."/jingyan/".$rs_pro["id"].".html");
  12. }
  13. $sql_search_pro="select id from mdaima_news where pass='1' order by id desc limit 30";
  14. $result_pro=$mysqli->query($sql_search_pro);
  15. while ($rs_pro=$result_pro->fetch_assoc()){
  16. array_push($functionstr,"https://".$var_domain."/news/".$rs_pro["id"].".html");
  17. }
  18. $api = 'http://data.zz.baidu.com/urls?site=www.19jp.com&token=mdaima';
  19. $ch = curl_init();
  20. $options = array(
  21. CURLOPT_URL => $api,
  22. CURLOPT_POST => true,
  23. CURLOPT_RETURNTRANSFER => true,
  24. CURLOPT_POSTFIELDS => implode("\n", $functionstr),
  25. CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
  26. );
  27. curl_setopt_array($ch, $options);
  28. $result = curl_exec($ch);
  29. echo "向百度逐条批量推送数据成功!(已向百度推送[".$result."])";
  30. exit;
  31. }

最后生成的$result变量为返回成功后的状态信息。示例:[{"remain":99909,"success":1}]

以上就是PHP批量向百度主动推送URL加快收录的示例代码的详细内容,更多关于PHP批量向百度主动推送URL加快收录的示例代码的资料请关注九品源码其它相关文章!