SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy back to previous page after login..

    Dear All,

    My program works like this...

    when user click on login button in my index.php, login.php will be shown and user requires to enter user name and password.

    So when user login successfully, he will be brought back to the previous page (eg index.php in this case, it might be blog.php or other depends from where the user click the login button.)

    i know there is a way using this:

    Code:
    header($url);
    $link = $_SERVER['HTTP_REFERER'];
    header($link);
    but this is not work for me as when user submit the login form, it actually process in the same login.php form. $_SERVER['HTTP_REFERER'] will be override to login.php..

    how can i get the user back to the page before he go into login form?

    thank you!
    newbie...

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Set a new hidden field in your login page with the value being the page to send the user back to. In the simplest case this would be:
    Code:
    <input type="hidden" name="return" value="<?=$_SERVER['HTTP_REFERER']?>" />
    But this could be fairly insecure because it can return the user off-domain so you may want to check that out. Then on the next page just do:
    Code:
    header('Location: ' . $_POST['return']);
    Happy switcher to OS X running on a MacBook Pro.

    Zend Certified Engineer

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by xmitchx View Post
    Set a new hidden field in your login page with the value being the page to send the user back to. In the simplest case this would be:
    Code:
    <input type="hidden" name="return" value="<?=$_SERVER['HTTP_REFERER']?>" />
    But this could be fairly insecure because it can return the user off-domain so you may want to check that out. Then on the next page just do:
    Code:
    header('Location: ' . $_POST['return']);
    but then when user submit the login form, $_SERVER['HTTP_REFERER'] will be override, is it?
    newbie...

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm.... is it possible to have a back 2 pages function for this?
    newbie...

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by liyenn View Post
    but then when user submit the login form, $_SERVER['HTTP_REFERER'] will be override, is it?
    No... the $_SERVER['HTTP_REFERER'] won't even affect your $_POST['return'] variable. You set the hidden variable on the previous page:
    Code:
    <input type="hidden" name="return" value="<?=$_SERVER['HTTP_REFERER']?>" />
    This will be changed to something like this:
    Code:
    <input type="hidden" name="return" value="/previous_page.php" />
    Since PHP will put the value of the variable in there. Then on the next page $_POST['return'] will be "/previous_page.php." It doesn't affect the server variable at all.
    Happy switcher to OS X running on a MacBook Pro.

    Zend Certified Engineer

  6. #6
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    xmitchx,

    thanks for your reply again...
    maybe i did something wrong in my last try just now..
    i'll try out your suggestion again..

    thanks ya!
    newbie...


Bookmarks

Posting Permissions

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