redirecting user back from the page he came after login

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • realin
    Contributor
    • Feb 2007
    • 254

    redirecting user back from the page he came after login

    hi guys,

    this one is simple for you :P

    its like.. after login how would i redirect the user back to the page he came from ..

    first i have to choose a language ?
    shall i do it in JS or php using window.location or header respectively ?

    Second thing i want to know is how to send the URLs from one page to another, shall i use an array which is passed on everypage ? or i should use a hidden field ?


    thanks and regards
    Realin !
    Last edited by realin; Oct 18 '07, 06:20 PM. Reason: Email notification
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    You could save the $_SERVER['HTTP_REFERER'] url on entering the login page, and then redirect to that url once the login form has been submitted and processed.

    Something like:
    [code=php]
    # Check if the form has been submitted
    if(isset($_POST['formSubmitButt on'])) {
    # Process the form

    # Redirect
    header("Locatio n: ". $_SESSION['loginRedirect'];
    }
    else {
    # Save the referer URL
    $_SESSION['loginRedirect'] = $_SERVER['HTTP_REFERER'];

    # Print your form
    }


    [/code]

    Comment

    • realin
      Contributor
      • Feb 2007
      • 254

      #3
      Originally posted by Atli
      Hi.

      You could save the $_SERVER['HTTP_REFERER'] url on entering the login page, and then redirect to that url once the login form has been submitted and processed.

      Something like:
      [code=php]
      # Check if the form has been submitted
      if(isset($_POST['formSubmitButt on'])) {
      # Process the form

      # Redirect
      header("Locatio n: ". $_SESSION['loginRedirect'];
      }
      else {
      # Save the referer URL
      $_SESSION['loginRedirect'] = $_SERVER['HTTP_REFERER'];

      # Print your form
      }


      [/code]

      thanks a lot, taht was helpfull.. will look forward to it

      Comment

      Working...