时间:2021-07-01 10:21:17 帮助过:4人阅读
$arr = array('A','B','C','D','E');
$file = 'data.log';
// 获取未显示过的page,如全部已显示,则重新赋值
if(file_exists($file)){
$data = json_decode(file_get_contents($file),true);
if(!$data){
$data = $arr;
}
}else{
$data = $arr;
}
// 判断用户是否访问过,如访问过直接显示上次访问的结果,否则抽取最前一页,写入用户cookies
if(isset($_COOKIE['show'])){
$result = $_COOKIE['show'];
}else{
$result = array_splice($data,0,1);
$result = array_pop($result);
setcookie('show',$result,time()+3600);
file_put_contents($file, json_encode($data), true);
}
echo $result;
$content = array('A', 'B', 'C', 'D', 'E');
!($cookie = intval($_COOKIE['content'])) && setcookie('content', $cookie = rand(0, count($content) - 1));
echo $content[$cookie];