Jump to content

header() oddity


Koobazaur

Recommended Posts

Hey,

 

I am working on a user management system and each pageload one of my included files verifies that the session hasn't expired. If it has, it should redirect back to login page. I use header("Location: http://me/login.php") for this and while it does redirect, it works really weird. For instance, if I get redirected to the login page and check page source, I see the code from the previous page (although displayed in my browser is the login page)!

 

Also, after logging in, you should get either redirected to a default page OR the page you were at before. I use header("Location: ") for that as well and every time I get re-directed to default page. I've done shitloads of testing and my code structure is alright - it gets to the proper header and inputs the proper page url to redirect. Yet, the page that loads is the default login page...

 

Case in point: header is being reeeaaallly weird, or I am not using it correctly. Any idea what I am doing wrong?

Link to comment
Share on other sites

try adding on exit(header("location: http://me/login.php")); that way it will stop executing the current page and move to login.php.  Also login.php should really only be the form/maybe a few trackers so don't load it down with php

 

I have put die() right after header and now my pages redirect correctly. However, I still get a wrong source code for the page as described...

 

As for not overloading login.php, on the contrary. It is not just a login form, but it's a full login/logout handling file that uses my predefined cUser class that (in turn) handles all my Session and Userdatabase handling. As it is, whenever there is something that happens to my User, I just redirect to login.php and it handles it. Logging in, Logging out, re-authenticating if a session expires (and then sending user back where he left off) are all the things that my login.php takes care of and, once he examines all the cases, it prints out a login form with any errors that may have happened (like invalid user/name pass, outside login attempt blocked etc.)

 

 

Though I am planning to convert it into it's own include .php file that just does all that and sets a few globals (like, did login succeed or where to redirect after successful login etc.) so I create login forms/handling wherever I want on my website.

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.