Jump to content

header and sessions not working together


bruckerrlb

Recommended Posts

Hey everyone,

 

I'm trying to do a little security here, I have a login script it stores three sessions, session id, the username and the permission level of the user, the last two are database sessions, and I can get them to print out fine on the page, but what is killing me is when I do this

 

if ($_SESSION['sessid'] != session_id()) {
header("Location:index.php");
}

Nothing seems to happen. What I mean is I logout, kill the session, try to hit a page that has this code in it, and it still lets me in. I don't understand why, there is no output getting sent before this, just start_session();

 

I've even done tests to see if $_SESSION['sessid'] and session_id() are the same, and they both show up different, but it lets me in. Does anyone know why this could be happening?

 

Link to comment
Share on other sites

hey Guys,

 

I had tried with the space there and not there on the header, finally I changed up the code a little, works a little better

 

if ($_SESSION['sessid'] != session_id() || $$_SESSION['sessid'] == ' ') {
header("Location:index.php");
}

 

I'm sure thats not the best way but it seems to be working now, weird

Link to comment
Share on other sites

You need an exit; statement after your header() redirect to prevent the remainder of the code on the page from being executed/accessed. All a hacker needs to do is ignore the header and he can access the page the same as if that code was not present.

 

As to your original problem in the first post in this thread, you were probably getting a header() error (output sent before the header statement) and without the exit; statement the code on the page was executed the same as if the header statement was not even there.

 

Are you developing and debugging this code on a system with error_reporting set to E_ALL and display_errors set to ON so that you would know if you were or were not getting any header errors?

 

Edit: The $$_SESSION['sessid'] == ' ' part of your logic expression makes no sense and is probably always FALSE.

 

 

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.