Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    PHP Display Telephone Number On Referrer

    I have used the php below to show a different telephone number in the header of the site depending upon where the visitor comes from. The code below works but looses the original referrer information upon click of own site links, defaulting the telephone number back to the generic number.

    Is there away to save it to the session, maybe the start session and save session is not done correct?

    Thanks for any help

    .............................................................................

    <?PHP
    session_start();
    if(!isset($_SESSION[’referrer’])){

    $referer = strtolower($_SERVER["HTTP_REFERER"]);

    if (strstr($referer,"site1"))
    {
    echo("<h1>Telephone Number1</h1>");
    }
    else if (strstr($referer,"site2"))
    {
    echo("<h1>Telephone Number2</h1>");
    }
    else if (strstr($referer,"site3"))
    {
    echo("<h1>Telephone Number3</h1>");
    }
    else if (strstr($referer,"site4"))
    {
    echo("<h1>Telephone Number4</h1>");
    }
    else
    {
    echo("<h1>Telephone Number5</h1>");
    } $_SESSION[’referrer’] = $referrer; // store session data
    }?>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You're spelling your $referrer variable two different ways: $referer, and $referrer.

    You should also keep this little factoid in mind (copied from the PHP manual):

    'HTTP_REFERER': 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.

  • Users who have thanked Fumigator for this post:

    dremes (11-05-2009)

  • #3
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    for some reason when i write referrer all with the same spelling upon clicking on internal links all referrer telephone numbers are lost.

    I know HTTP Referrer is not that reliable, but what else could be considered I looked at java script referrer but think that is less reliable then php referrer.

    Please if you could change the code to the way you think it should be and repost it, maybe its just me not been able to spell!

    Many thanks for your help

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    And you have session_start() at the top of every page?

  • #5
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    yes as the php is in the template of the header, so the whole script would be repeated on everypage.

  • #6
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Oh-- look at your logic, I just noticed that you don't do anything if $_SESSION['referrer'] is set. Don't you want to use that value if it's set?

  • #7
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Yes i do want to use it to display the referrer number, I need to call back what was set in the session, but how??

    thanks

  • #8
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Assign value to $referrer based on whether $_SESSION['referrer'] is set.

    PHP Code:
    if (isset($_SESSION['referrer'])) {
        
    $referrer $_SESSION['referrer'];
    } else {
        
    $referrer strtolower($_SERVER["HTTP_REFERER"]);


  • #9
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    looks like this now --- but only the last else echo tel5 shows from all referrers. If theres a fix you could help with I am more then happy to send you on some form of payment for your efforts,, thanks

    <?PHP
    if (isset($_SESSION['referrer'])) {
    $referrer = $_SESSION['referrer'];
    } else {
    $referrer = strtolower($_SERVER["HTTP_REFERER"]);

    if (strstr($referer,"essential"))
    {
    echo("<h1>Telephone Number1</h1>");
    }
    else if (strstr($referer,"site2"))
    {
    echo("<h1>Telephone Number2</h1>");
    }
    else if (strstr($referer,"site3"))
    {
    echo("<h1>Telephone Number3</h1>");
    }
    else if (strstr($referer,"site4"))
    {
    echo("<h1>Telephone Number4</h1>");
    }
    else
    {
    echo("<h1>Telephone Number5</h1>");
    } $_SESSION[’referrer’] = $referrer; // store session data
    }?>

  • #10
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Don't you want to be running through all that code to echo the <h1> tag regardless of the results of your first "if" statement?

  • #11
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Yes i need to echo the correct telephone number h1 tag based on original referrer which is stored in the session...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •