john.muckley Posted April 7, 2013 Share Posted April 7, 2013 (edited) 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 April 8, 2013 by john.muckley Quote Link to comment https://forums.phpfreaks.com/topic/276667-best-way-to-show-page-only-if-user-logged-in/ Share on other sites More sharing options...
Rifts Posted April 8, 2013 Share Posted April 8, 2013 try changing this line: $_SESSION['active'] ='TRUE'; to $_SESSION['active'] ='true'; Quote Link to comment https://forums.phpfreaks.com/topic/276667-best-way-to-show-page-only-if-user-logged-in/#findComment-1423473 Share on other sites More sharing options...
trq Posted April 8, 2013 Share Posted April 8, 2013 Or better yet, use booleans instead of strings. Quote Link to comment https://forums.phpfreaks.com/topic/276667-best-way-to-show-page-only-if-user-logged-in/#findComment-1423476 Share on other sites More sharing options...
john.muckley Posted April 8, 2013 Author Share Posted April 8, 2013 try changing this line: $_SESSION['active'] ='TRUE'; to $_SESSION['active'] ='true'; I did this, but it made no difference at all Quote Link to comment https://forums.phpfreaks.com/topic/276667-best-way-to-show-page-only-if-user-logged-in/#findComment-1423506 Share on other sites More sharing options...
mac_gyver Posted April 8, 2013 Share Posted April 8, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/276667-best-way-to-show-page-only-if-user-logged-in/#findComment-1423508 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.