You can't do any of this without using some external storage. If its unique to an individual client, then you may best use sessions.
PHP Code:
<?php
error_reporting (E_ALL | E_STRICT);
session_start();
$files = array();
$path = "./questions/";
if (!isset($_SESSION['visited']))
{
$_SESSION['visited'] = array();
}
if ($dh = @opendir($path))
{
while (false !== ($file = readdir($dh))
{
if ($file != "." && $file != ".." && is_file($file))
{
$files[] = $path . $file;
}
}
closedir($dh);
// mkay, here remove what's already been visited
$aUnvisited = array_diff($files, $_SESSION['visited']);
if (count($aUnvisited) > 0)
{
// Still have places to go
shuffle($aUnvisited);
$sToInclude = array_shift($aUnvisited);
$_SESSION['visited'][] = $sToInclude;
include($sToInclude);
}
else
{
// Everything has been visited. Put your end case scenario here.
}
}
else
{
printf("Could not open %s for reading" . PHP_EOL, $path);
}
Something like that. Untested, but works alright in my head