PHP批量向百度主动推送URL加快收录的示例代码
更新:2023-02-06 16:35:06
人气:659
来源:本站原创
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}]
推荐的文章
随手记
PHP经验分享
- ● Pluginmysql_native_passwordreported:''mysql_native_password'isdeprecate问题
- ● PHP实现计算CRC-16/MODBUS校验位
- ● MySQLSUM在没有符合查询条件时返回结果为空的处理办法
- ● 如何开启PHP8的JIT提升运行速度
- ● 钉钉API接口-用PHP+Curl实现获取用户信息
- ● 钉钉API接口-用PHP+Curl实现获取应用Access_Token
- ● 在PHP中使用CURL,“撩”服务器只需几行——phpcurl详细解析和常见大坑
- ● MySQLInnodb并发涉及参数说明
- ● mysql参数调优之innodb_thread_concurrency、innodb_concurrency_tickets合理的使用cpu性能
- ● PHP用fsockopen检测指定IP端口是否开启可用