Remember the previous page?

Discussion in 'PHP' started by UCDaZ, Sep 3, 2008.

  1. #1
    I'm trying to figure out what this process is called.

    Example:
    When I'm NOT logged into the site, and I want to click on the action on page 1, it will bring me to the login page. Once I'm logged in, it will forward me back to page 1.

    How does it remember which state I was in? What is this process called, so I can search for google tutorials?
     
    UCDaZ, Sep 3, 2008 IP
  2. lanmonkey

    lanmonkey Active Member

    Messages:
    549
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Store the url in a session variable. when your script logs the user in you can regenerate their session ID without losing the data stored in any session variables by using session_regenerate_id()
    then, once logged in, simply read the url from the session variable and redirect the user there.

    If you want to preserve the exact state of the page before the user logs in so that you can return the user there afterwards you can put this info into session variables on every page load or put it in the URL like this:

    www.fatblunt.com/roll_me_a_fat_one.php?page=somepage&id=23&sort=asc&is_my_blunt_fat=yes&got_munchies=yes
    Code (markup):
    When returned to this page all the variables can be pulled from the URL and the page setup in the same way as before.
     
    lanmonkey, Sep 4, 2008 IP
  3. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #3
    Example action.php needs people to be logged in.
    In action php do a header("location: login.php") if not logged in.
    in login.php set a cookie for each visit. cookie stores the url of previous page ($_SERVER[HTTP_REFERRER])
    Once login is successful, redirect to url in cookie.
    Write empty string in cookie when they logout.
    regards :)
     
    JEET, Sep 4, 2008 IP
  4. kapinder

    kapinder Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Store the url of the page in session and after login use the header function to go to that url.
     
    kapinder, Sep 4, 2008 IP
  5. UCDaZ

    UCDaZ Active Member

    Messages:
    180
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #5
    Does it matter if I use a cookie or a session to store the previous page?
     
    UCDaZ, Nov 2, 2008 IP
  6. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #6
    ^Will not make much of a difference.
    Also, you may have a hidden form field that sends the URL of the page to the login script. If login is successful, the visitor is redirected back.
     
    rohan_shenoy, Nov 2, 2008 IP