欢迎您来到,李雷博客 | PHP博客        登录  |  注册

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

更新:2023-02-06 16:35:06
人气:564
来源:本站原创
A+

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

if ($action=="baidu_everyone"){
	
	$functionstr = array();
	
	$sql_search_pro="select id from mdaima_it where pass='1' order by id desc limit 30";
	$result_pro=$mysqli->query($sql_search_pro);
	while ($rs_pro=$result_pro->fetch_assoc()){
		array_push($functionstr,"https://".$var_domain."/it/".$rs_pro["id"].".html");
	}

	$sql_search_pro="select id from mdaima_jingyan where pass='1' order by id desc limit 30";
	$result_pro=$mysqli->query($sql_search_pro);
	while ($rs_pro=$result_pro->fetch_assoc()){
		array_push($functionstr,"https://".$var_domain."/jingyan/".$rs_pro["id"].".html");
	}
	
	$sql_search_pro="select id from mdaima_news where pass='1' order by id desc limit 30";
	$result_pro=$mysqli->query($sql_search_pro);
	while ($rs_pro=$result_pro->fetch_assoc()){
		array_push($functionstr,"https://".$var_domain."/news/".$rs_pro["id"].".html");
	}
	
	$api = 'http://data.zz.baidu.com/urls?site=www.mdaima.com&token=mdaima';
	$ch = curl_init();
	$options =  array(
		CURLOPT_URL => $api,
		CURLOPT_POST => true,
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_POSTFIELDS => implode("\n", $functionstr),
		CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
	);
	curl_setopt_array($ch, $options);
	$result = curl_exec($ch);

	echo "向百度逐条批量推送数据成功!(已向百度推送[".$result."])";
	exit;
}

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

推荐的文章
# 发表我的评论
  /     /  
# 最近评论
暂时还没有评论,要不要说点什么?
  Ads by Google
  联系博主
Hello,本博客系统采用PHP和MySql开发,程序开发完全是因为个人爱好,是自己纯手写PHP源代码,未采用任何PHP框架!
QQ:858353007   微信号:lileihot123
网站地图
会员服务
关于我们
QQ:858353007
 
广告服务
加我微信
移动端访问
 
 
Copyright © 2014- 2024 www.mdaima.com All Rights Reserved.
李雷博客,专注PHP经验、PHP教程及PHP源代码开源下载分享的PHP博客!   ICP备案号:京ICP备10202169号-4