Save the Original Referer

Discussion in 'PHP' started by vanshake, Nov 16, 2008.

  1. #1
    anyone know how i can save the original site referer in a variable for use in a later page?

    for ex:

    homepage.php
    <?php
    session_start();
    $_session["orig_referer"] = $_server[http_referer];

    // do stuff then user goes to page2.php
    ?>

    page2.php
    <?
    session_start();
    echo $_session["orig_referer"];
    ?>

    what i want echoed in page2.php is the original referer, but unfortunately i get homepage.php as the referer.

    any thoughts on how to save the original refer w/o cookies, DB, passing in URL or saving to a file?
     
    vanshake, Nov 16, 2008 IP
  2. garrettheel

    garrettheel Peon

    Messages:
    341
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    are you including the file with $_session["orig_referer"] = $_server[http_referer]; in every page?
    if that's the case, you can use an if statement to stop it being reset

    
    if (!isset($_SESSION['orig_referer']))
    {
           $_session["orig_referer"] = $_server[http_referer];
    }
    
    Code (markup):
     
    garrettheel, Nov 16, 2008 IP
  3. vanshake

    vanshake Peon

    Messages:
    95
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    nope. just once on the homepage, but apparently it gets reset automatically on each succeeding page.
     
    vanshake, Nov 16, 2008 IP
  4. garrettheel

    garrettheel Peon

    Messages:
    341
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you set it in the $_SESSION variable, it should not get reset.

    Edit: unless they click on another page and visit the homepage again. In that case, the code I gave you will also work.
     
    garrettheel, Nov 16, 2008 IP
  5. vanshake

    vanshake Peon

    Messages:
    95
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    it would seem that way but it isn't.

    for ex:
    on the homepage i did as a test:
    $_session[xyz]="hello";
    $_session[orig_referer]=$_server[http_referer];

    then
    echo $_session[xyz].$_session[orig_referer]
    would output:
    hello [then the true orig referer here]

    on page2.php
    session_start();
    echo $_session[xyz].$_session[orig_referer]
    would output:
    hello homepage.php

    the $_session[orig_referer] seems to change as the referer changes despite any new assignment.
     
    vanshake, Nov 16, 2008 IP