Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
Thread: Redirecting to Login Page
09-09-2011, 09:59 PM #1
- Join Date
- May 2009
- Thanked 65 Times in 65 Posts
Redirecting to Login Page
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 #2
- Join Date
- Oct 2008
- Some say it's everything.
- Thanked 397 Times in 390 Posts
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.
The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
See Mediocrity in its Infancy
It's usually a good idea to start out with this at the VERY TOP of your CSS:
Seek and you shall find... basically: validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting
09-09-2011, 10:29 PM #3
- Join Date
- Feb 2011
- Your Monitor
- Thanked 527 Times in 514 Posts
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.
See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/
Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!