refferer..

Discussion in 'PHP' started by deemainer, Nov 7, 2008.

  1. #1
    Hi all

    Does anyone possibly know how i can effeciently get the referrer in php. The script i have seems to only work occasionaly. I need something that will say to the user

    hello... you came from x.com/pagex/something.html

    to go back to x.com click here.

    Thanks
     
    deemainer, Nov 7, 2008 IP
  2. bugcoder

    bugcoder Peon

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    dont know what you are already using but try this to get the previous url and store it in variable or in href to move back

    $backurl=$_SERVER['HTTP_REFERER'];
     
    bugcoder, Nov 7, 2008 IP
  3. deemainer

    deemainer Active Member

    Messages:
    351
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    78
    #3
    thanks bug coder...heres what ive got:
    <?
    $referer = $_SERVER['HTTP_REFERER'];
    $refererhome = $_SERVER['HTTP_HOST'];
    ?>
    you came from:<?echo "$referer"; ?>

    return to the homepage of the site you came from please click here :
    <a href="http://<?echo "$refererhome"; ?> ">click here</a>

    It doesnt seem to work though?
     
    deemainer, Nov 7, 2008 IP
  4. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #4
    If a user came from a site wich opened your site in a new tab/window the referer is empty, otherwise the code above should work!
     
    EricBruggema, Nov 7, 2008 IP
  5. deemainer

    deemainer Active Member

    Messages:
    351
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    78
    #5
    thats what i thought.

    At the momemt im using it from a 404 (so 404 redirects from one site to another with script) That shouldnt make any difference should it. And its not in a new window or anythingm its just a straight redirect.

    So that should work you think? Thanks for your helpby the way
     
    deemainer, Nov 7, 2008 IP