I am trying to write a PHP script that collects website data.
I am trying to write a function that checks if the referrer was a search engine, if it is it gets the search engine domain and the keywords used.
Any tips?
PHP Web Analytics
Started by adzeds, Oct 27 2009 04:14 PM
5 replies to this topic
#1
Posted 27 October 2009 - 04:14 PM
|
|
|
#2
Guest_Jordan_*
Posted 27 October 2009 - 04:27 PM
Guest_Jordan_*
You'll need to use $_SERVER['HTTP_REFERER'] to determine that information. There is also a PHP class you can use or take ideas from located here: CReferrer (referer) - PHP Classes
#3
Posted 29 October 2009 - 04:16 PM
Here is some of my code, does not seem to work though!
Any ideas?
Any ideas?
function searchEngine()
{
$refer = parse_url($_SERVER['HTTP_REFERER']);
$host = $refer['host'];
if(strstr($host,'google'))
{
$searchengine = "yes";
$sedomain = "Google";
return $searchengine;
}
elseif(strstr($host,'yahoo'))
{
$searchengine = "yes";
$sedomain = "Yahoo";
return $sedomain;
}
elseif(strstr($host,'msn'))
{
$searchengine = "yes";
$sedomain = "MSN";
return $sedomain;
}
}
function getKeywords()
{
$refer = parse_url($_SERVER['HTTP_REFERER']);
$host = $refer['host'];
$refer = $refer['query'];
if(strstr($host,'google'))
{
//do google stuff
$match = preg_match('/&q=([a-zA-Z0-9+-]+)/',$refer, $output);
$querystring = $output[0];
$querystring = str_replace('&q=','',$querystring);
$keywords = explode('+',$querystring);
return $keywords;
}
elseif(strstr($host,'yahoo'))
{
//do yahoo stuff
$match = preg_match('/p=([a-zA-Z0-9+-]+)/',$refer, $output);
$querystring = $output[0];
$querystring = str_replace('p=','',$querystring);
$keywords = explode('+',$querystring);
return $keywords;
}
elseif(strstr($host,'msn'))
{
//do msn stuff
$match = preg_match('/q=([a-zA-Z0-9+-]+)/',$refer, $output);
$querystring = $output[0];
$querystring = str_replace('q=','',$querystring);
$keywords = explode('+',$querystring);
return $keywords;
}
else
{
//else, who cares
return false;
}
}
#4
Posted 31 October 2009 - 08:46 AM
#5
Posted 02 November 2009 - 12:29 AM
The:
$keywords & $sedomain
variables seem to be returned blank!
How do I return more that one variable from a function?
$keywords & $sedomain
variables seem to be returned blank!
How do I return more that one variable from a function?
#6
Posted 04 November 2009 - 08:35 AM
Anyone got any advice on this!
Really want to create a good script to collect web stats.
Anyone know any existing scripts that i could customize?
Really want to create a good script to collect web stats.
Anyone know any existing scripts that i could customize?


Sign In
Create Account


Back to top









