timmah1 Posted June 2, 2008 Share Posted June 2, 2008 I'm trying to make sure a person is logged in before accessing a certain form, But even if I'm logged in, it redirects me to the login page //check to make sure the user is logged in if(isset($_SESSION['USERNAME']) == FALSE) { header("Location: " . $config_basedir . "/login.php"); } require("header.php"); //This is where the form will show if user is logged in Am I doing this right? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/108450-redirect-login/ Share on other sites More sharing options...
unidox Posted June 2, 2008 Share Posted June 2, 2008 Do you have session_start() at the top of each page? Quote Link to comment https://forums.phpfreaks.com/topic/108450-redirect-login/#findComment-555990 Share on other sites More sharing options...
timmah1 Posted June 2, 2008 Author Share Posted June 2, 2008 yes I do Quote Link to comment https://forums.phpfreaks.com/topic/108450-redirect-login/#findComment-555992 Share on other sites More sharing options...
.josh Posted June 2, 2008 Share Posted June 2, 2008 I'd also like to point out that if (isset($_SESSION['USERNAME']) == FALSE) { is overkill. if ($_SESSION['USERNAME']) { will do. As far as your problem goes...do you have session_start() on top of ALL your pages, including the one tha tset the session var in the first place? If so, are you sure you spelled it right? If so...then how do you know you're logged in? Because if all that other stuff checks out, then there's no reason this piece of code shouldn't work, unless that require("header.php"); is somehow redirecting you or something. Quote Link to comment https://forums.phpfreaks.com/topic/108450-redirect-login/#findComment-556001 Share on other sites More sharing options...
metrostars Posted June 2, 2008 Share Posted June 2, 2008 Try doing echo $_SESSION['USERNAME'] to check that the session is deffo set. Quote Link to comment https://forums.phpfreaks.com/topic/108450-redirect-login/#findComment-556013 Share on other sites More sharing options...
timmah1 Posted June 2, 2008 Author Share Posted June 2, 2008 ok I have this at the top of my page session_start(); require("config.php"); echo $_SESSION['SESS_USERNAME']; //check to make sure the user is logged in if ($_SESSION['SESS_USERNAME']) { header("Location: " . $config_basedir . "/login.php"); } When I log in, it shows the username The problem now, it lets me view the form even when I'm not logged in Quote Link to comment https://forums.phpfreaks.com/topic/108450-redirect-login/#findComment-556025 Share on other sites More sharing options...
timmah1 Posted June 2, 2008 Author Share Posted June 2, 2008 I got it to work, but I had to do this if(isset($_SESSION['SESS_LOGGEDIN']) == FALSE){ header("Location: " . $config_basedir . "/login.php"); } And it works fine now. Thanks for all your help Quote Link to comment https://forums.phpfreaks.com/topic/108450-redirect-login/#findComment-556039 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.