Jump to content

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

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.