Redirect previous page after log in

Discussion in 'PHP' started by salayhin, Feb 23, 2010.

  1. #1
    I want to redirect the previous page after the log in form submit and form processing. Actually i have code as below, but it shows a error.....plz help me.

    I have a log in page and i use this code to fine current page.
    <input name="last_url" type="hidden" value="<?=$_SERVER['HTTP_REFERER']?>"/>

    and after submit the log in page i use this code for form processing.

    <?php
    session_start();
    require("config/common_db.inc");
    db_connect();
    $Last_Url=$_GET["last_url"];
    //$_SESSION=$Last_Url; $msgEmail=''; if (...cument to handle the request. Plz help me.
     
    salayhin, Feb 23, 2010 IP
  2. darkblade

    darkblade Peon

    Messages:
    187
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Ok, your header is wrong.

    Should be header("Location: ".$Last_Url);

    You are actualy redirecting to url "echo $Last_Url"

    Hope that helps.

    You should really fix your mysql, it is very easy to mysql injection on your site. Make sure you filter your input to your mysql.
    $username = addslashes ($_POST['MemberID'])
    $password = addslashes($_POST['Password'])

    If you really want to be good, make sure that $username is only numbers.
     
    Last edited: Feb 23, 2010
    darkblade, Feb 23, 2010 IP
  3. salayhin

    salayhin Peon

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks For your reply.
    But it does not work properly.
    Actually it stay on same page i think it has a
    <input name="last_url" type="hidden" value="<?=$_SERVER['HTTP_REFERER']?>"/>

    this coding problem.
    Help me.
     
    salayhin, Feb 23, 2010 IP
  4. darkblade

    darkblade Peon

    Messages:
    187
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Before you submit your login page, check the source code to see if value equals to the correct page.

    HTTP_REFERER is not good anyways.

    From the php site:
    The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
     
    darkblade, Feb 23, 2010 IP
  5. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #5
    Your redirect error is because of "echo" word in the header command. Remove echo word. use:
    header("location: $last_url");
    Use the " sign instead of ' sign and it should work.
    Thanks :)
     
    JEET, Feb 23, 2010 IP