View Single Post
Old 07-02-2012, 05:05 PM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by krispol View Post
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);
}
Fou-Lu is offline   Reply With Quote