Quote:
Originally Posted by krispol
Hey
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:
PHP Code:
<?php
session_start();
error_reporting (E_ALL | E_STRICT);
$files = array();
$path = "./randompages/";
$sRedirectTo = 'http://yoursite.com/index.php';
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)
{
// 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.
header('Location: ' . $sRedirectTo);
exit();
}
}
else
{
printf("Could not open %s for reading" . PHP_EOL, $path);
}