php - save the referring site's url

Discussion in 'PHP' started by datrader, Feb 8, 2012.

  1. #1
    I’d like to save the referring page to my site – only external sources and then pass it in a session to another page where I log this url.
    My site uses the index.php file to connect to all pages of the site (like a global include). So my problem is that I do record the referring url, but it is erased if a user passes from page to page – my script writes the previous page, instead of just saving the entrance url and that’s it.

    Anyone can help here?
     
    datrader, Feb 8, 2012 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    hi
    put this in index.php


    session_start();

    // Make sure the REFERER value is

    if(strstr($_SESSION['HTTP_REFERER'], "index.php") == false)
    {
    // Save the value in the $_SESSION array
    $_SESSION['origionalref'] = $_SERVER['HTTP_REFERER'];
    }
     
    kmap, Feb 8, 2012 IP
  3. asepdanii

    asepdanii Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I also need this guide again please help me how?
     
    asepdanii, Feb 8, 2012 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    The variable is $_SERVER['HTTP_REFERER'];

    However, there's no way to reliably do this. The referrer is not set on all browsers and can be forged. It is not a reliable method of identifying where a visitor came from. If the referrer can be used for anything that could be a potential security or operational risk, expect it to happen at some point.
     
    jestep, Feb 8, 2012 IP
  5. HostingLynx

    HostingLynx Active Member

    Messages:
    106
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    83
    Articles:
    10
    #5
    Just to let you know people can manipluate HTTP referals so make sure to sanatize your strings.
     
    HostingLynx, Feb 8, 2012 IP