Jump to content

Redirect Login


timmah1

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/108450-redirect-login/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/108450-redirect-login/#findComment-556001
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/108450-redirect-login/#findComment-556025
Share on other sites

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.