Can you post any errors please. I noticed one thing. Try this:
PHP Code:
<?php
session_start();
error_reporting (E_ALL | E_STRICT);
$files = array();
$path = "images/";
$sRedirectTo = 'http://yoursite.com/index.php';
$_SESSION['numQuestions'] = 2; // Number of questions presented per session
if (!isset($_SESSION['visited']))
{
$_SESSION['visited'] = array();
}
if ($dh = @opendir($path))
{
while (false !== ($file = readdir($dh)))
{
if ($file != "." && $file != ".." && is_file($path . $file))
{
$files[] = $path . $file;
}
}
closedir($dh);
// mkay, here remove what's already been visited
$aUnvisited = array_diff($files, $_SESSION['visited']);
print_r($aUnvisited);
if ((count($aUnvisited) > 0) && (count($aUnvisited) < $_SESSION['numQuestions']))
{
// 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.
if ((count($aUnvisited) == 0) || ($_SESSION['numQuestions'] > count($aUnvisited)))
{
unset($_SESSION['visited']);
}
unset($_SESSION['numQuestions']);
header('Location: ' . $sRedirectTo);
exit();
}
}
else
{
printf("Could not open %s for reading" . PHP_EOL, $path);
}
?>
Edit: Just noticed another potential error so updated.
Edit: Been updated again. One problem is that the remaining unanswered questions (over mulitple restarts) might be greater than the questions per page. For this it'll just reset like if there were none.