当我单击下一步时,从数组列表中打开随机的 PHP 页面


open random php pages from array list when I click next

我陷入了死胡同。我已经为此工作了 3 周,但没有结果。

我有 10 个 php 页面(1.php2.php、...、10.php)和一个起始页(start.php)。

我想做的只是随机化 10 页而不重复,所以当我在start.php中单击"下一步"时,它应该转到 10 页之一(例如,假设它转到 4.php )。当我在4.php中单击"下一步"时,它应该重定向到 10 页中的另一个页面,除了 4.php .

它应该继续这样做,直到显示所有数字(1.php - 10.php)。此时,它应该再次随机化。当我在显示的最后一个数字中单击"下一步".php时,它应该随机化该数字并返回到随机列表中的第一个。

这是我到目前为止所拥有的:

start.php

<?php $vidcount = 1; ?>
<? include ("source.php"); ?>
<a href="$nextvid[$vidcount].php">next page</a>

source.php

<?php 
include ("start.php");
$numbers = range(1, $total_songs);
if(($vidcount == $total_songs)||($vidcount == 1)){
shuffle($numbers);
$vidcount = 1;
}
$nextvid[1] = $numbers[0];
$nextvid[2] = $numbers[1];
$nextvid[3] = $numbers[2];
$nextvid[4] = $numbers[3];
$nextvid[5] = $numbers[4];
$nextvid[6] = $numbers[5];
$nextvid[7] = $numbers[6];
$nextvid[8] = $numbers[7];
$nextvid[9] = $numbers[8];
$nextvid[10] = $numbers[9];
?>

1.php2.php , ... 10.php

<?php
include("source.php");?>
<?php echo $vidcount; ?>
<a href="testrun[<?php echo $nextvid[$vidcount];  ?>].php">next page</a>
<?php $vidcount++;?>

1.php - 10.php具有相同的代码。我还有一个source.php它应该跟踪显示的数字,并在显示所有数字时重新洗牌。

请帮忙。我将非常感谢我能得到的任何帮助。

您不必使用上面的代码,如果您有不同的想法,只要我得到的代码有效,我不介意从头开始。

首先,为什么只有十个文件,而你可以只有一个文件并在URL中?id=X?但没关系。

最好的办法是使用会话变量。像这样:

<?php
    session_start();
    if( !isset($_SESSION['sequence']) || !$_SESSION['sequence']) {
        $_SESSION['sequence'] = shuffle(range(1,10));
    }
    $next = array_shift($_SESSION['sequence']);
    // now use $next to create your "Next page" link.
?>