View Single Post
Old 07-01-2012, 05:19 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 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
You can't do any of this without using some external storage. If its unique to an individual client, then you may best use sessions.
PHP Code:
<?php
error_reporting 
(E_ALL E_STRICT);
session_start();
$files = array();
$path "./questions/"

if (!isset(
$_SESSION['visited']))
{
    
$_SESSION['visited'] = array();
}

if (
$dh = @opendir($path))
{
    while (
false !== ($file readdir($dh))
    {
        if (
$file != "." && $file != ".." && is_file($file))
        {
            
$files[] = $path $file;
        }
    }
    
closedir($dh);
    
    
// mkay, here remove what's already been visited
    
$aUnvisited array_diff($files$_SESSION['visited']);
    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.
    
}
}
else
{
    
printf("Could not open %s for reading" PHP_EOL$path);
}
Something like that. Untested, but works alright in my head
Fou-Lu is offline   Reply With Quote