随机跳转源码~容易

2019-12-30 16:49:27 -0800
<?php
//数组data,url是跳转网址,weight是权重,权重的总和不论
//可以多个地址随机,数量不论,注意最后一条没有逗号
$urldata = array(
array('url'=>'http://www.baidu.com', 'weights'=>1),
array('url'=>'http://www.qq.com', 'weights'=>2),
array('url'=>'http://www.163.com', 'weights'=>3),
array('url'=>'http://www.sina.com.cn', 'weights'=>4)
);

$tzurlarr = getConsultant($urldata);
$tz_url = $tzurlarr['url'];
//echo $tz_url;

header("location:".$tz_url);

function getConsultant(array $data){
$weight = 0;
$users = array();
foreach ($data as $one) {
$oneWeight = (int)$one['weights'] ? $one['weights'] : 1;
$weight += $oneWeight;
for ($i = 0; $i < $oneWeight; $i ++) {
$users[] = $one;
}
}
return $users[rand(0, $weight-1)];
}
演示 http://go.2sm.xyz/go.php
«Newer      Older»

Back to home

Subscribe | Register | Login | N