Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Thanked 67 Times in 67 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).
    "Yeah science!"

  • #2
    Senior Coder Rowsdower!'s Avatar
    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: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Your Monitor
    Thanked 546 Times in 533 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.
    I can't really think of anything to write here now...


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts