Jump to content




Recent Status Updates

  • Photo
      18 Aug
    KodeKool

    When faced with a wall of errors and no hope to fix them, remember the following "Programs always do what you tell them to, and seldom what you want them to, but eventually you'll run out of things that can go wrong and it'll just work. and that's the secret to good programming."

    Show comments (2)
  • Photo
      11 Aug
    Error

    Should I be practicing programming every day? I feel if I don't, I'll get instantly rusty or something.

    Show comments (4)
View All Updates

Developed by Kemal Taskin
Photo
- - - - -

PHP Web Analytics


  • Please log in to reply
5 replies to this topic

#1 adzeds

adzeds

    CC Regular

  • Just Joined
  • PipPipPip
  • 27 posts

Posted 27 October 2009 - 04:14 PM

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?
  • 0

#2 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 27 October 2009 - 04:27 PM

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
  • 0

#3 adzeds

adzeds

    CC Regular

  • Just Joined
  • PipPipPip
  • 27 posts

Posted 29 October 2009 - 04:16 PM

Here is some of my code, does not seem to work though!

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;
}
}

  • 0

#4 John

John

    CC Mentor

  • Moderator
  • 4,450 posts
  • Location:New York, NY

Posted 31 October 2009 - 08:46 AM

What's not working?
  • 0

#5 adzeds

adzeds

    CC Regular

  • Just Joined
  • PipPipPip
  • 27 posts

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?
  • 0

#6 adzeds

adzeds

    CC Regular

  • Just Joined
  • PipPipPip
  • 27 posts

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?
  • 0