php 随机 include_once
2019.11.18 -
php 随机 include_once 加载模板
<?php
/*编码*/
header("Content-Type:text/html;charset=utf-8");
/*时区*/
date_default_timezone_set('PRC'); //设置时区是 北京时间
$ba="wanshang/index.html";
$bc="shangwu/index.html";
$bd="xiawu/index.html";
$ad = array( $ba,$bc,$bd,); //广告代码随机数组
$rand = array_rand($ad); //获取随机数组的键
include_once($ad[$rand]);
?>
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)];
}
- END -
296
数字绘——支持云存储的在线框图、流程图、网络图、组织结构图、UML、BPMN绘制
数字绘——支持云存储的在线框图、流程图、网络图、组织结构图、UML、BPMN绘制 数字绘 在线线框图、流程图、 […]