View Single Post
Old 07-02-2012, 06:24 PM   PM User | #9
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 Fou-Lu View Post
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);
}

Thank you so much for helping me!!!

It is almost working now. At first I got all my questions randomly without repeating, only thing was that it was also displaying some code on the background, probably, how many questions are left or smth.

After the last question where it was supposed to redirect to http://mypage.com it just showed a blank page with a text: Array () on it.

Now that I refreshed/closed and opened the page and tried to start answering again, it right away shows me that blank page with Array () on it.

Any idea?

Last edited by krispol; 07-02-2012 at 06:27 PM..
krispol is offline   Reply With Quote