View Full Version : Redirecting to Login Page

09-09-2011, 09:59 PM
What would be the best method for redirecting users to a login page (e.g. if they try to access a page that requires logging in? For example, if you go to http://runescape.com, click on 'account', and then click on anything inside the account menu, you get redirected to a login page before being sent to the actual page.

There's a lot of ways this could be done, I'm just looking for the most efficient, in particular, a method that won't interrupt the page transfer (e.g. if the page is reached via a form, I don't want the post data to be lost during the login process).

09-09-2011, 10:06 PM
I usually just use $_SESSION to store anything that I will need to remember for use after a login redirect. Then the bottom of the login script (when the user actually logs in) checks that $_SESSION array for certain keys and, if present, acts accordingly on them.

This can be simply to return the user to the page they came from or it can be for form processing. Really you can do whatever you like.

09-09-2011, 10:29 PM
As Rows says, storage in the session is good for temporary storage. I capture the $_REQUEST array and store that. That way everything that was submitted via $_GET or $_POST is saved. You may also wish to look at serialising the data using serialize() and then storing it in the DB. You could also use var_export for the same thing again storing $_REQUEST in the DB.

$_REQUEST doesn't handle files though so you'll need to save those and then save them into your data array under a key called files so that you have access to them after login.