本帖最后由 fdipzone 于 2015-04-06 17:24:06 编辑
<br />$arr = array('A','B','C','D','E');<br />$file = 'data.log';<br /><br />// 获取未显示过的page,如全部已显示,则重新赋值<br />if(file_exists($file)){<br /> $data = json_decode(file_get_contents($file),true);<br /> if(!$data){<br /> $data = $arr;<br /> }<br />}else{<br /> $data = $arr;<br />}<br /><br />// 判断用户是否访问过,如访问过直接显示上次访问的结果,否则抽取最前一页,写入用户cookies<br />if(isset($_COOKIE['show'])){<br /> $result = $_COOKIE['show'];<br />}else{<br /> $result = array_splice($data,0,1);<br /> $result = array_pop($result);<br /> setcookie('show',$result,time()+3600);<br /> file_put_contents($file, json_encode($data), true);<br />}<br /><br />echo $result;<br />
------解决思路----------------------<br /><?php<br />$content = array('A', 'B', 'C', 'D', 'E');<br />!($cookie = intval($_COOKIE['content'])) && setcookie('content', $cookie = rand(0, count($content) - 1));<br />echo $content[$cookie];<br />