<?php
$lastNo=$this->getGameLastNo(14);
header('Content-type: application/xml');
echo'<?xml version="1.0" encoding="utf-8"?>';
echo '<xml><row expect="'.$lastNo['actionNo'].'" opencode="'.randKeys().'" opentime="'.$lastNo['actionTime'].'"/></xml>';
/* 生成随机数 */
function randKeys($len=5){
$str='0123456789';
$rand='';
for($x=0;$x<$len;$x++){
$rand.=($rand!=''?',':'').substr($str,rand(0,strlen($str)-1),1);
}
return $rand;
setInterval(function(){randkeys()},1000);
}
?>
上面代码生成随机数只要一刷新就变化了,我想固定几分钟内刷新不变化,后来我请教了个网友他说加setInterval(function(){randkeys()},1000);这段代码就可以控制,但我加了后打开网页是空白的,请问哪里有问题?还有加这代码有用吗?
$lastNo=$this->getGameLastNo(14);
header('Content-type: application/xml');
echo'<?xml version="1.0" encoding="utf-8"?>';
echo '<xml><row expect="'.$lastNo['actionNo'].'" opencode="'.randKeys().'" opentime="'.$lastNo['actionTime'].'"/></xml>';
/* 生成随机数 */
function randKeys($len=5){
$str='0123456789';
$rand='';
for($x=0;$x<$len;$x++){
$rand.=($rand!=''?',':'').substr($str,rand(0,strlen($str)-1),1);
}
return $rand;
setInterval(function(){randkeys()},1000);
}
?>
上面代码生成随机数只要一刷新就变化了,我想固定几分钟内刷新不变化,后来我请教了个网友他说加setInterval(function(){randkeys()},1000);这段代码就可以控制,但我加了后打开网页是空白的,请问哪里有问题?还有加这代码有用吗?
第一:函数return之后的代码是不会执行的
第二:只有js有setInterval这个函数个人建议:
如果想固定不变,可以传递cookie值设定过期时间,没有过期返回原值,过期就重新生成值;
也可以用高速缓存来做
其中'.$lastNo['actionNo'].' 和.$lastNo['actionTime'].'读的是数据库,我想在数据表新建个栏目取名datahao 然后在这栏目填写自己固定好的数值供opencode="'.randKeys().'"读取,请问opencode="'.randKeys().'" 标签应该怎么改读取数据?我不懂编译!
想让每台机器生成的随机数都不同,那就连接上ip地址和user-agent做种子
这样完全不依赖cookie了