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 :)

Edited by john.muckley
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.