1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Remember previous page a user was on...

Discussion in 'PHP' started by fatabbot, Apr 15, 2007.

  1. #1
    Some sites have this feature that when you click on a link that requires a login first, they automatically go to a login form.
    But, after login they get redirected to the page that they were previously viewing.

    How does the page know where the user is coming from? Where is this URL stored? In the $_GET or $_Session or something else?
     
    fatabbot, Apr 15, 2007 IP
  2. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #2
    You store the link in a hidden textbox in login page and whenever you get login just fetch the link from hidden text and rederect to the page using header('Location: Redirect PageURL')
     
    Subikar, Apr 15, 2007 IP
  3. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You could use GET or SESSION but as Subikar says a hidden POST value is probably best.

    No real problems with GET that I know about but SESSION can lead to difficulties when a user has multiple tabs/windows open browsing the same site.
     
    streety, Apr 15, 2007 IP
  4. VishalVasani

    VishalVasani Peon

    Messages:
    560
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes, You can accomplish this task with GET,Post or Session variable easily...No great coding required for this task....
     
    VishalVasani, Apr 15, 2007 IP
  5. fatabbot

    fatabbot Well-Known Member

    Messages:
    559
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    138
    #5
    How to use $_POST when the pages are different?

    Say A is the page i'm visiting, with a link on it to page B which requires a login first.
    The login page is on page C. Where can I create a hidden textbox the surfer gets redirected from page C to B ?
     
    fatabbot, Apr 15, 2007 IP
  6. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #6
    lets suppose you want user to be logged in before viewing news.php, redirect user to login.php?lastpage=news.php

    Now on login.php, save the page name in session, as

    $_SESSION['lastpage'] = $_GET['lastpage'];

    When user logged in successfully, redirect him/her to old page using following code,

    header("location:" . $_SESSION['lastpage']);

    Hope this helps.
     
    designcode, Apr 15, 2007 IP
    fatabbot likes this.
  7. fatabbot

    fatabbot Well-Known Member

    Messages:
    559
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    138
    #7
    Thanks... :)
     
    fatabbot, Apr 15, 2007 IP
  8. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #8
    Thanks for REP :D
     
    designcode, Apr 15, 2007 IP
  9. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #9
    Suggestion of "designcode" is good but I think for this type of things you shouldn't use $_SESSION because if cookie is disable then it will not work. But disabling of COOKIE is rare cases but you must keep in mind of this. :)
     
    Subikar, Apr 15, 2007 IP
  10. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #10
    $_SESSION is just for example, if you are running a big application, I can bet you won't be relying on PHP's $_SESSION thing, you will be handling session yourself (using DB or whatever), won't you :)?

    Anyway cookies are disabled rarely these days, because i think most peoples are now aware that cookies can't harm your PC, only they can make you fat :D
     
    designcode, Apr 15, 2007 IP
  11. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #11
    Thats right designcode in this modern generation no one want to be fat any way good suggestion. :).

    fatabbot You can implement the system according to designcode suggestion too.
     
    Subikar, Apr 28, 2007 IP