View Single Post
Old 07-03-2012, 07:10 PM   PM User | #25
krispol
New Coder

 
Join Date: May 2012
Posts: 52
Thanks: 12
Thanked 0 Times in 0 Posts
krispol is an unknown quantity at this point
Quote:
Originally Posted by dan-dan View Post
I added 'page' to the session. Think this should work:

PHP Code:
<?php
session_start
();
error_reporting (E_ALL E_STRICT);
$files = array();
$path "./randompages/"
$sRedirectTo 'http://yoursite.com/index.php';
$_SESSION['page'] = 0;

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);
        echo 
"You are on question " $_SESSION['page'] += " of " count($files) ;
    }
    else
    {
        
// Everything has been visited.  Put your end case scenario here.
        
session_unset(); 
        
header('Location: ' $sRedirectTo);
        exit();
    }
}
else
{
    
printf("Could not open %s for reading" PHP_EOL$path);

?>
Actually it only made the code visible on the background of the questions (showing on what question I am and how many left etc). It didn't give me an opportunity to have only few questions out of 20, even if I changed that 0 in the end of that 'page' session o 10. But I probably did it wrong?
krispol is offline   Reply With Quote