Topic: require user to be logged in to view directory

<?php
define('PUN_ROOT', './forums/');
include 'forums/include/common.php';

function login_menu() {
global $pun_user;

function directory($result) {  
     
     $handle=opendir("./files");  
     while ($file = readdir($handle)) {  
     if ($file == "." || $file == ".." || $file == "index.php") { } else { print "<a href=$file>$file</a><br>\n"; } 
       
     }  
     closedir($handle);  

return $result;  
}  

if ($pun_user['is_guest']) {
  echo "<br />Please <a href=\"http://animelink.be/forums/register.php\">Register Here</a> or <a href=\"http://animelink.be/forums/login.php\">Login Here</a><br />";
    }
else {
echo "<b>Manga Downloader</b><p>";
echo directory($result);
echo "<p><a href=\"http://localhost/pantasia\">Go Back To Pantasia</a>";
}
}
?>

what this is suppose to do is, when the user is logged in, he can see the files in the directory
when the user is NOT logged in, he sees links to register and log in

i dont get any errors
but all i see is a blank screen
when im logged in and when im not logged in

i called it "file.php" and its like this in my directory:

file.php
/forums/            <-punbb directory

can someone fix this?

Re: require user to be logged in to view directory

You need to call the function before anything will happen.

login_menu();

3 (edited by raptrex 2005-12-27 15:03)

Re: require user to be logged in to view directory

<?php
define('PUN_ROOT', './forums/');
include 'forums/include/common.php';

function login_menu() {
global $pun_user;

function directory($result) {  
     
     $handle=opendir("./files");  
     while ($file = readdir($handle)) {  
     if ($file == "." || $file == ".." || $file == "index.php") { } else { print "<a href=$file>$file</a><br>\n"; } 
       
     }  
     closedir($handle);  

return $result;  
}  

if ($pun_user['is_guest']) {
  echo "<br />Please <a href=\"http://animelink.be/forums/register.php\">Register Here</a> or <a href=\"http://animelink.be/forums/login.php\">Login Here</a><br />";
    }
else {
echo "<b>Manga Downloader</b><p>";
echo directory($result);
echo "<p><a href=\"http://localhost/pantasia\">Go Back To Pantasia</a>";
}
}
login_menu();
?>

i put login_menu(); at the end of the script

but it will show the directory whether im logged in or not

this happens in firefox

in opera

it shows the 2 links whether im logged in or not

Re: require user to be logged in to view directory

You probably have the path wrong, change the include to require and see what it thinks.

Re: require user to be logged in to view directory

ok it works
just had to clear my cookies and it worked