View Full Version : How do i change the displayed phone number based on refer url
travisnps
04-20-2010, 10:15 PM
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.
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
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.
djr33
04-21-2010, 03:15 AM
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).
travisnps
04-21-2010, 04:55 AM
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.
djr33
04-21-2010, 05:32 AM
Use traq's code for that. Add an elseif (..... line like the first if to add extra URLs.
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.)
hmsnacker123
04-21-2010, 03:48 PM
Heres an example of the elseif statement (Thanks traq)
<?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
Heres an example of the elseif statement (Thanks traq)
<?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
// ...
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.