Kryptronic Software Support Forum

You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.

#1 06-16-2009 09:33:26

wyattea
Member
Registered: 01-07-2006
Posts: 1650

checking SE referrer info to print text on splash page

I have a competitor that prints my city when I visit their site, implying that they may be located or at least ship to my city.  It's not the best implementation because for the gift industry, people are usually shipping to another city.  I'd like to try and do something similar and check the referrer string for a specific instances of all my major city delivery areas. For example, if the user has 'toronto' in the referrer, i'll print something referencing that city (e.g. Delivering gifts in Toronto Ontario and throughout Canada).  There are maybe 15 to 20 cities I'll do this for so it won't be too bloated, and the default is just a standard tag line.

I'm doing research on what type of functions to use and it's getting very confusing. preg_match, strstr, strpos, etc. Here's a snipped of code I edited but I'm hoping someone can give me a hint whether I'm trying to reinvent the wheel or if there's a much simpler solution (ignore incorrect # of parenthesis, I have bothered formatting the code properly):

Code:

<?php

class search_keywords
{
var $referer;

var $keys;

var $sep;

function search_keywords()
{
$this->referer = ”;
$this->sep = ”;

if ($_SERVER['HTTP_REFERER'] OR $_ENV['HTTP_REFERER'])
{
$this->referer = urldecode(($_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] : $_ENV['HTTP_REFERER']));
$this->sep = (eregi(’(\?q=|\?qt=|\?p=)’, $this->referer)) ? ‘\?’ : ‘\&’;
}
}

function get_keys()
{
if (!empty($this->referer))
{

if (referrer == 'toronto') [this would be where strpos/strstsr/preg_match would be used]

{

}

else

{

print my usual stuff

}
);


?>

Offline

 

#2 06-16-2009 09:41:44

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: checking SE referrer info to print text on splash page

The referrer is simply a URL and can not be trusted anyway so I'm not quite sure I understand how you might get something usual such as a city name out of a URL.

Offline

 

#3 06-16-2009 10:18:29

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: checking SE referrer info to print text on splash page

Dave, why must you question my genius? smile Here's a sample of keywords used to come into my site (i cut/pasted a small section from a long list):

Code:

baby gift basket toronto     
baby gift baskets calgary   
baby gift baskets edmonton     
baby gift winnipeg 
baby gifts 
baby gifts delivered     
baby gifts delivery toronto    
baby gifts montreal     
barrie flower shops     
basket delivery toronto

In the US, most searches don't include city or province references, but people who search for delivery in Canada know that they need to put the city otherwise they'll get all those websites that are US based that don't ship to Canada.

As you can see, montreal, toronto, winnipeg, edmonton, calgary are all used to visit my site. I want to take the URL and if it CONTAINS a city name, I can print a specific piece of text referencing that city.  If a visitor comes in with 'giftdeliveryinedmontoncanada', my check for 'edmonton' will see it in that string (url).  If it's NOT there, no big deal, the 'else' part of my test will just print what is currently being printed on my page.

There is no downside, because if they don't use one of the keywords (remember I said the top 15 to 20 cities I ship to), it just displays what it has always displayed in the space I'm planning to use for it.

Offline

 

#4 06-16-2009 10:20:16

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: checking SE referrer info to print text on splash page

Another note:

Code:

 http://www.google.ca/search?hl=en&q=Fathers+day+Delivery+ideas+-+Hamilton+Ontario&meta=

Here's a sample string - I would just want to check for 'hamilton' (case insenstive). If they spell it wrong, no big deal, goes to default text.

Offline

 

#5 06-16-2009 10:33:20

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: checking SE referrer info to print text on splash page

Not questioning your genius at all James just pointing out that most of the time a referring URL won't contain any useful information let alone city specific detail.

CCP provides a global variable that contains the referrer information which you may obtain using:

Code:

$referrer = $this->globals('khxc_session.referer');

If you have a list of specific cities you want to check for I'd build an array with the names and zip through the array and check the referrer for each name.

Code:

<?php
$cities   = array('toronto','hamilton','ontario');  # use all lower case here, we'll normalize the referrer data while checking it
$referrer = $this->globals('khxc_session.referer');
foreach ($cities as $cityname) {
    if (strtolower(strpos($referrer,$cityname)) === false ) {  # not found
        continue;  # go on to the next city name
    } else {
        # do something here cause we found the city in the referrer
    }
}
?>

Offline

 

#6 06-16-2009 10:42:47

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: checking SE referrer info to print text on splash page

Ok good, you still think I'm a genius smile I'm not trying to deal with the times there's no city information...only when there IS smile If it's only 15% of the time, that's fine.

Thanks for the code, but I think you're missing my point. I'm not trying to put text that generalizes based on a set of cities. Instead of foreach, I'll use a bunch of if-elses that test each referer string to see if it contains the city name (there's be 20 or if elses). If it CONTAINS that particular city string, it'll print text that INCLUDES that particular city name.

So no $cities array. Basically here's how I see it (not proper code, just training of thought).

Code:

If (strstr(referer_string, 'edmonton'))

{
 print 'Delivering gifts throughout Edmonton Alberta and across Canada!';
}

else if (strstr(referer_string, 'vancouver'))

{
 print 'Delivery gifts throughout Vancouver British Columbia and across Canada!'';
}

...

else 
{
print "Delivering gifts all across Canada!";
}

Is that workable? I think it makes sense?

Last edited by wyattea (06-16-2009 10:43:38)

Offline

 

#7 06-16-2009 10:46:11

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: checking SE referrer info to print text on splash page

Same code, just plug in your slug and use the name of the city.

Code:

<?php
$cities   = array('toronto','hamilton','ontario');  # use all lower case here, we'll normalize the referrer data while checking it
$referrer = $this->globals('khxc_session.referer');
foreach ($cities as $cityname) {
    if (strtolower(strpos($referrer,$cityname)) === false ) {  # not found
        continue;  # go on to the next city name
    } else {
        print 'Delivering gifts throughout ' . ucfirst($cityname) . '.';
    }
}
?>

If you don't want it be that general pick off the city name and use your if/else.

Offline

 

#8 06-16-2009 21:52:42

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: checking SE referrer info to print text on splash page

Seems nice and simply. Tried implementing but I can't seem to find this syntax error:

Code:

<?php
$cities = array('toronto,'mississauga','oakville','newmarket','aurora','scarborough','brampton','markham','montreal','laval','vancouver','surrey','burnaby','ottawa','gatineau','calgary','edmonton','quebec','winnipeg','hamilton','burlington','london','kitchener','cambridge','waterloo','halifax','oshawa','whitby','victoria','windsor','saskatoon','regina','sherbrooke','barrie','kelowna','abbotsford','sudbury','kingston','saguenay','guelph','moncton','brantford','peterborough','chatham','lethbridge','kamloops','nanaimo','belleville','sarnia','fredericton','charlottetown');  # use all lower case here, we'll normalize the referrer data while checking it
$referrer = $this->globals('khxc_session.referer');
foreach ($cities as $cityname) {
    if (strtolower(strpos($referrer,$cityname)) === false ) {  # not found
        continue;  # go on to the next city name
    } else {
        print 'GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in ' . ucfirst($cityname) . ' and across Canada!';
    }
}
?>

Parse error: syntax error, unexpected T_STRING, expecting ')' in /home/wyattea/grenvillestation.com/city-referer-tag-script.php on line 2

Any idea?

Offline

 

#9 06-16-2009 21:56:35

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: checking SE referrer info to print text on splash page

ok, can't believe I missed the end quote after toronto...smile now I run it and this displays:

Code:

GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Toronto and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Mississauga and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Oakville and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Newmarket and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Aurora and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Scarborough and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Brampton and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Markham and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Montreal and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Laval and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Vancouver and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Surrey and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Burnaby and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Ottawa and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Gatineau and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Calgary and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Edmonton and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Quebec and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Winnipeg and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Hamilton and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Burlington and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in London and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Kitchener and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Cambridge and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Waterloo and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Halifax and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Oshawa and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Whitby and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Victoria and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Windsor and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Saskatoon and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Regina and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Sherbrooke and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Barrie and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Kelowna and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Abbotsford and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Sudbury and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Kingston and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Saguenay and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Guelph and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Moncton and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Brantford and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Peterborough and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Chatham and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Lethbridge and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Kamloops and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Nanaimo and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Belleville and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Sarnia and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Fredericton and across Canada!GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in Charlottetown and across Canada! Parse error: syntax error, unexpected T_STRING, expecting ')' in /home/wyattea/grenvillestation.com/city-referer-tag-script.php on line 2

It basically printed every one...I need an 'exit' out of the foreach loop...but same error message as before.

Last edited by wyattea (06-16-2009 21:59:00)

Offline

 

#10 06-17-2009 05:55:14

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: checking SE referrer info to print text on splash page

Breaking out if you find something would be helpful I suppose smile This version will only print your tag line if something is found.  If you wanted to use a generic line if a city isn't found simply add an else to the if !empty after the foreach is done.

Code:

<?php
$cities   = array('toronto','mississauga','oakville','newmarket','aurora','scarborough','brampton','markham','montreal','laval','vancouver','surrey','burnaby','ottawa','gatineau','calgary','edmonton','quebec','winnipeg','hamilton','burlington','london','kitchener','cambridge','waterloo','halifax','oshawa','whitby','victoria','windsor','saskatoon','regina','sherbrooke','barrie','kelowna','abbotsford','sudbury','kingston','saguenay','guelph','moncton','brantford','peterborough','chatham','lethbridge','kamloops','nanaimo','belleville','sarnia','fredericton','charlottetown');  # use all lower case here, we'll normalize the referrer data while checking it
$referrer = $this->globals('khxc_session.referer');
$tagline  = '';
foreach ($cities as $cityname) {
    if (strtolower(strpos($referrer,$cityname)) === false ) {  # not found
        continue;  # go on to the next city name
    } else {
        $tagline = 'GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in ' . ucfirst($cityname) . ' and across Canada!';
        break;  # we don't need to check any further

    }
}

if (!empty($tagline)) {
    print $tagline;
}
?>

Offline

 

#11 06-17-2009 23:22:17

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: checking SE referrer info to print text on splash page

Hi Dave...I figured out the need for 'break', just forgot to post a reply about it. I thought it was working yesterday and planned to work out the appearance of it this weekend but I just realized that when I 'tested' it, I visited my website and it showed the message with the first city (toronto), but I had visited the site direct and not through any keywords. I also tried visiting site through google having used other keywords in the list and not toronto. It only displays the statement with toronto filled in.

Any idea why? Here's my code:

Code:

<?php
$cities = array('toronto','mississauga','oakville','newmarket','aurora','scarborough','brampton','markham','montreal','laval','vancouver','surrey','burnaby','ottawa','gatineau','calgary','edmonton','quebec','winnipeg','hamilton','burlington','london','kitchener','cambridge','waterloo','halifax','oshawa','whitby','victoria','windsor','saskatoon','regina','sherbrooke','barrie','kelowna','abbotsford','sudbury','kingston','saguenay','guelph','moncton','brantford','peterborough','chatham','lethbridge','kamloops','nanaimo','belleville','sarnia','fredericton','charlottetown');  # use all lower case here, we'll normalize the referrer data while checking it
$referrer = $this->globals('khxc_session.referer');
foreach ($cities as $cityname) {
    if (strtolower(strpos($referrer,$cityname)) === false ) {  # not found
        continue;  # go on to the next city name
    } else {
        print 'GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in ' . ucfirst($cityname) . ' and across Canada!';
        break;
    }
}
?>

Last edited by wyattea (06-17-2009 23:23:12)

Offline

 

#12 06-18-2009 06:27:13

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: checking SE referrer info to print text on splash page

Try this instead James (changed the logic test to positive instead of negative):

Code:

<?php
$cities = array('toronto','mississauga','oakville','newmarket','aurora','scarborough','brampton','markham','montreal','laval','vancouver','surrey','burnaby','ottawa','gatineau','calgary','edmonton','quebec','winnipeg','hamilton','burlington','london','kitchener','cambridge','waterloo','halifax','oshawa','whitby','victoria','windsor','saskatoon','regina','sherbrooke','barrie','kelowna','abbotsford','sudbury','kingston','saguenay','guelph','moncton','brantford','peterborough','chatham','lethbridge','kamloops','nanaimo','belleville','sarnia','fredericton','charlottetown');  # use all lower case here, we'll normalize the referrer data while checking it
$referrer = $this->globals('khxc_session.referer');
$tagline  = '';
foreach ($cities as $cityname) {
    if (strtolower(strpos($referrer,$cityname)) != false ) {
        $tagline = 'GrenvilleStation.com delivers gift baskets, candy bouquets and flowers in ' . ucfirst($cityname) . ' and across Canada!';
        break;
    }
}
if (!empty($tagline)) {
    print $tagline;
} else {
    print 'This is the stock tagline when there is no city match';
}
?>

Offline

 

Board footer