Originally Posted by Fou-Lu
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);
Thank you so much for helping me!!!
It is almost working now. At first I got all my questions randomly without repeating, only thing was that it was also displaying some code on the background, probably, how many questions are left or smth.
After the last question where it was supposed to redirect to http://mypage.com
it just showed a blank page with a text: Array () on it.
Now that I refreshed/closed and opened the page and tried to start answering again, it right away shows me that blank page with Array () on it.