Originally Posted by krispol
Nope, no error, just a blank page. I didn't put anything into the else condition, what should I put there though?
Anything will do, sounds to me like you want a redirect. Dan posted a header to change the location.
The problem you'll have is that is_file requires a valid file. It can be relative, but I missed the path in the check. Use this instead:
error_reporting (E_ALL | E_STRICT);
$files = array();
$path = "./randompages/";
$sRedirectTo = 'http://yoursite.com/index.php';
$_SESSION['visited'] = array();
if ($dh = @opendir($path))
while (false !== ($file = readdir($dh)))
if ($file != "." && $file != ".." && is_file($path . $file))
$files = $path . $file;
// mkay, here remove what's already been visited
$aUnvisited = array_diff($files, $_SESSION['visited']);
if (count($aUnvisited) > 0)
// Still have places to go
$sToInclude = array_shift($aUnvisited);
$_SESSION['visited'] = $sToInclude;
// Everything has been visited. Put your end case scenario here.
header('Location: ' . $sRedirectTo);
printf("Could not open %s for reading" . PHP_EOL, $path);