How $_SERVER['HTTP_REFERRER'] works?

Discussion in 'PHP' started by srobona, Jul 15, 2007.

  1. #1
    Hello,

    I've got some problems with $_SERVER['HTTP_REFERRER'] function. I need to do something like this:

    I have 3 pages,
    1.index.php
    2. login.php
    3. member.php (need login to access)

    If any one tries to go from index.php to member.php without login, the member.php will redirect the user to login.php, and after successful login,
    the user will be redirected to the member.php.

    I need to solve this problem by using the referer function. Can any one help me in this regard? Solution will be highly appreciated. :)
     
    srobona, Jul 15, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    The referrer is sent by the browser, and not all browsers send it by default. Plus it can be easily modified. That means you shouldn't rely on it.

    Work with sessions instead. Start a session in login, and check for it in member.php. If there's none, or it's not valid, throw an error.
     
    nico_swd, Jul 15, 2007 IP
  3. Doskono

    Doskono Peon

    Messages:
    153
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You should do this with session

    when you loggin you create a session['loggedin'] which you will want to put, if ($_SESSION['LOGGEDIN'] != TRUE) { echo "you are not authorized"; exit;}

    thats a better safer way.
     
    Doskono, Jul 15, 2007 IP
  4. srobona

    srobona Active Member

    Messages:
    577
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    88
    #4
    Thanks for the suggestions. I used session for login, but after successful login, how can i send the member to the page where he wanted to go before login?
     
    srobona, Jul 15, 2007 IP
  5. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #5
    using a redirect:
    header("Location: new_url");
     
    gibex, Jul 15, 2007 IP