Quote:
Originally Posted by dan-dan
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'] += 1 . " 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?