21,892
社区成员
![](https://csdnimg.cn/release/cmsfe/public/img/topic.427195d5.png)
![](https://csdnimg.cn/release/cmsfe/public/img/me.40a70ab0.png)
![](https://csdnimg.cn/release/cmsfe/public/img/task.87b52881.png)
![](https://csdnimg.cn/release/cmsfe/public/img/share-circle.3e0b7822.png)
<?php
$content = array('A', 'B', 'C', 'D', 'E');
!($cookie = intval($_COOKIE['content'])) && setcookie('content', $cookie = rand(0, count($content) - 1));
echo $content[$cookie];
$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;