php教程

百度推送完整PHP示例代码分享

php教程 51源码 2024-04-01 人阅读

网址改成你的域名,接口补充完整,保存代码到XX文件.php,访问一次就可以推送一次!

<?php  
$server_name = $_SERVER['SERVER_NAME'];
function rand_str($length = 5)
{
$str    = '';
$strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
$max    = strlen($strPol)-1;
for($i = 0; $i < $length; $i++)
{
$str   .=$strPol[rand(0,$max)];
}
   return $str;
}
$count = mt_rand(80,100);
$urls = array();
for ($i = 0; $i < $count; $i++) 
{ 
$urls[] = "https://www.251code.com".rand_str().'/'.rand_str().'.html';
}
$api = "http://data.zz.baidu.com/urls?site=https://www.251code.com&token=xxxxxxxxxxxxxxxxx";
$ch = curl_init();
$options =  array(
    CURLOPT_URL => $api,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => implode("\n", $urls),
    CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo $result;
?>



版权声明:文章搜集于网络,如有侵权请联系本站,转载请说明出处:https://www.51yma.cn/jiaocheng/php/1446.html
文章来源:
标签 百度推送