我正在尝试建立一个网站,以随机方式引导您浏览八个页面,而不重复页面,例如:第一个“filmpje4.php”,其中包含指向“filmpje8.php”的链接,它导致“ filmpje3.php',等等,直到所有八个页面都被访问过。
我环顾了几个网站,但我发现的代码似乎不起作用。我不断重复...
我尝试的代码示例:
$links = array('<a href="filmpje1.php">filmpje1</a>', [...]'<a href="filmpje8.php">filmpje8</a>');
// get users visited links to an array
$visited_links = explode('|', $_SESSION['visited_links']);
// remove visited links from links array
foreach($visited_links as $visited_link) {
unset($links[array_search($visited_link, $links)]);
}
// get a random link from unvisited links
$link = $links[rand(0, count($links)-1)];
// add the selected link to visited array
$visited_links[] = $link;
// save visited links to user session as | separated string
$_SESSION['visited_links'] = implode('|', $visited_links);
echo $link;