<?php
$files=[];
if(count($files)==0) {
foreach(glob("./*") as $d) {
$tmp=explode('.',$d);
$k=end($tmp);
if(is_file($d)&&strcasecmp($k,"txt")==0) {
array_push($files,$d);
}
}
}
$index=array_rand($files,1);
$source=$files[$index];
unset($files[$index]);
header('Location: '.$source);
?>
不是很懂PHP的小白,希望会PHP的大佬能帮忙看看,给点优化建议,谢谢谢谢。。。
解决方案:使用Session先记录所有文件,遍历完成移除,即可每次遍历不重复,Cookies也行,很简单。