Page 2 of 2

Posted: Tue May 25, 2004 2:43 pm
by DarkAngel
Ok last question, what would I put in other php files that only allow the file to be viewed if a user is logged in?

Posted: Tue May 25, 2004 2:53 pm
by DarkAngel
Ok I tried:

Code: Select all

<?php
<?php
if($_SESSION['loggedin'])
{
print "
what logged in members would see
";
} else {
print "
You do not have access to this file. Please log in.
";
}

?>

Posted: Tue May 25, 2004 9:59 pm
by tim
i dont know how you set it up

but put after the log-in (if indeed the name n password matched)

$_SESSION['auth'] = true;

then use:

Code: Select all

<?php
if ( !$_SESSION['auth'] ) { 
   // what not logged in users would see
} 
?>

Posted: Tue May 25, 2004 10:15 pm
by John Cartwright
Correct me if I'm wrong but is this correct:

Code: Select all

<?php
//Only works with register_globals being 'ON'.

unset( $_SESSION['variable'] );

?>
For the sake of mobility of the script,
use

Code: Select all

<?php

$_SESSION['variable'] = array();

?>
And I would also recommended avoiding statements like

if ($var) // do something

and get in the habbit of doing if (isset($var)) // do something

Once again for the sake of mobility and readability of the script.
Hense if you move to a server with register globals OFF.

Posted: Wed May 26, 2004 4:39 pm
by mendingo
Phenom wrote:Correct me if I'm wrong but is this correct:

Code: Select all

<?php
//Only works with register_globals being 'ON'.

unset( $_SESSION['variable'] );

?>
unset($_SESSION['variable']) works fine without register_globals being on.
If register_globals were on, then you could use unset($variable), but the former works universally.

Your second point is valid, unless you have explicity set $var as false before doing your check to make it true.

Posted: Wed May 26, 2004 4:52 pm
by jason
Tutorial on using Sessions: viewtopic.php?t=6521

Posted: Thu May 27, 2004 2:15 am
by DarkAngel
Ok my page is set out like this:

їcode]
|-----------------------------------------------------|
| Index page |
| |
| |---------------------------------------| Nav bar |
| | Iframe | |
| | | |
| | | |
| | | |
| | | |
| |---------------------------------------| |
| Login/Out Form|
|-----------------------------------------------------|
ї/code]
(the Iframe is contained in the index page as is the login/out form and the nav bar, but obviousley the iframe points to a seperate php file)

Now all the session code is in the index page, but when a user clicks a link (something like ?page=pie) in the nav bar it sets the iframe's src to whatever page= (and .php). Now, what do i have to put into pie.php to make it so it displays x if the user is logged in and y when the user isnt logged in?

Posted: Thu May 27, 2004 5:45 pm
by tim
hmm

did u even read the link provided by our good admin jason?

read it!!!!!!

:evil: