Results 1 to 8 of 8

Thread: How do i change the displayed phone number based on refer url

  1. #1
    Join Date
    Apr 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do i change the displayed phone number based on refer url

    I need to chagne the displayed phone number based on refer url, either with an image overlay or some sore of text rewrite. I would like it to display that phone number to that visitor for at least sever hours on all pages. My phone number is in the header currently it is an image.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    so, if a visitor comes to your site from example.com you'd want to display one phone number, but if they come from otherexample.net you'd want a different number to be shown?

    You can do this in php (probably w/javascript too, but not my specialty) fairly easily.
    PHP Code:
    <?php

    if(strstr('example.com'$_SERVER['HTTP_REFERER'])){ $phone '1(234)567-8910'; }
    else{ 
    $phone '1(019)876-5432'; }

    echo 
    $phone;

    ?>
    Of course, I'm not sure what your intention is, so I don't know if this would be a good solution or not. Why do you want different numbers to be displayed?

    In addition, HTTP_REFERER is set by the user agent, so sometimes it is wrong, faked, and/or missing. Basically, it can't really be trusted for important issues.

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    When doing something like this, based on the reasons mentioned above, it's a good idea to use this as an "educated guess" and allow the user to correct if there is a mistake. For example, have the phone number based on URL in bold and the other one as a backup.

    Also, it is possible that the referring URL may not just be wrong, but it also may not be sent at all (depending on browser/system settings). In this case, it is crucial that you need the else() statement above, not just a list of possible URLs. Of course this also applies because someone might come from an unexpected place (like a google search) or from a bookmark (no referrer).
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Apr 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    what I am wanting to do is tag my urls from different advertising campaigns so when for example someone comes from a Google campaign (A) it would have a variable that would make it show phone number (b) instead of our main phone number and if they were if referred by Yahoo phone number (c) and so on. I could then through my phone system report on what campaigns or ad groups are generating the most off line leads.

    If they come to our site direct they would get our main number and also of it was an organic search. I am only wanting to tag my Paid Referrals that happen offline since about 50% of or sales are offline phone sales. My phone system allows me to have as many phone numbers as I need to be able have 100 unique phones and tag each ad group I could I just need to be able to show the unique phone number whether it be an image overlay based on variable in the url or some other means like swapping a text based phone number.
    Last edited by travisnps; 04-21-2010 at 05:05 AM. Reason: adding more detail

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Use traq's code for that. Add an elseif (..... line like the first if to add extra URLs.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by djr33 View Post
    Add an elseif (..... line like the first if to add extra URLs.
    (each elseif('domain', $_SERVER['HTTP_REFERER']){ $phone = 'number'; } should go between the if() and the else. the else number should probably be your main phone number.)

  7. #7
    Join Date
    Mar 2008
    Posts
    122
    Thanks
    17
    Thanked 5 Times in 5 Posts

    Default

    Heres an example of the elseif statement (Thanks traq)
    PHP Code:
    <?php

    if(strstr('example.com'$_SERVER['HTTP_REFERER'])){ 
        
    $phone '1(234)567-8910'
    }
    elseif(
    strstr('anotherdomain.com'$_SERVER['HTTP_REFERER']))

        
    $phone '1(019)876-5432'
    }
    elseif(
    strstr('yetanotherdomain.com'$_SERVER['HTTP_REFERER']))
    {
        
    $phone '0(111)222-3333';
    }

    echo 
    $phone;

    ?>
    Link:
    http://uk2.php.net/elseif

  8. #8
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by hmsnacker123 View Post
    Heres an example of the elseif statement (Thanks traq)
    PHP Code:
    <?php

    if(strstr('example.com'$_SERVER['HTTP_REFERER'])){ 
        
    $phone '1(234)567-8910'
    }
    elseif(
    strstr('anotherdomain.com'$_SERVER['HTTP_REFERER']))

        
    $phone '1(019)876-5432'
    }
    elseif(
    strstr('yetanotherdomain.com'$_SERVER['HTTP_REFERER']))
    {
        
    $phone '0(111)222-3333';
    }

    echo 
    $phone;

    ?>
    Link:
    http://uk2.php.net/elseif
    Yes, but he needs to include a final else line at the end:
    PHP Code:
    <?php
    // ...
    else{ $phone '1(234)567-8910'/*default phone number*/ }

    echo 
    $phone;

    ?>
    otherwise, if the referrer doesn't match any domains on the list, the phone number will be left blank.

Bookmarks

Posting Permissions

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