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

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

本篇内容主要分享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.19jp.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}]

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