Jump to content

best way to show page only if user logged in?


john.muckley

Recommended Posts

hey guys!

 

I was wondering what the best or preferred way of only showing certain pages to users when logged in is?

 

I tried declaring a session variable 'active' as TRUE, and then checking for it on my 'logged in' page, but that didnt seem to work :(

 

I used this in the login page on successful login...

 

session_start();
$_SESSION['active'] ='TRUE';
header("location:userhome.php");

 

When i log in, i dont get any errors and it redirects me to userhome.php, which is...

 

 

<?php
include("session.php");

$sessioncheck = $_SESSION['active'];
echo 'You are logged in!! Session status is: ' . $sessioncheck ;

?>

 

and session.php looks like this...

<?php
session_start();
if ($_SESSION['active'] != 'true') {
header("location:login.php?response=4");
exit();
}
?>

 

but "logged in" or not, i get "You are logged in! Session status is: ", with no actual variable.

 

am i overlooking something?

 

Any help is appriciated!!

 

Thanks :)

if nothing is displayed by the original code, then either you are not actually setting it or one of your session_start statement(s) is missing or is not working or you have managed to clear it at some point.

 

is your php's error reporting set to display all errors?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.