PDA

View Full Version : Referrer Tracking



nikomou
11-23-2005, 03:18 PM
Hey Guys,

I'm looking for a php script that will show the website and keyword used (if from a search engine) to find my site...


For example:

http://www.google.co.uk/search?hl=en&q=mysite&meta=

$site = google
$keyword = mysite

I would like this to work for:
MSN
Google
Yahoo
and Ask Jeeves..

If the referer is not a search engine:

www.examplereferrersite.com/bla-bla-bla.html

$site = examplereferrersite.com
$keyword = (blank)

Does anyone know how to do this??

Twey
11-23-2005, 03:33 PM
Ooh, yes. Well, I can do google, anyway. You should be able to figure out the rest.

$st = $_SERVER['HTTP_REFERER'];
$host;
$keywords;
if(strpos($st, "google")) {
$host = "google";
$st = substr(strpos($st, "q="));
$st = substr(0, strpos($st, "&")) > 1 ? strpos($st, "&") : strlen($st);
$st = substr(0, substr($st, "&") > 1 ? strpos($st, "&") : strlen($st);
$st = preg_replace('/\+/g', " ", urldecode($substr));
$keywords = $st;
}Making it work with other search engines is a simple matter of working out what their GET variables are called, and so on and so forth.
Note: this is a more-or-less direct port of the Javascript script I wrote in this thread (http://www.dynamicdrive.com/forums/showthread.php?t=5489).