Jump to content

PHP Web Analytics

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
adzeds

adzeds

    Newbie

  • Members
  • PipPip
  • 27 posts
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?

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
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
adzeds

adzeds

    Newbie

  • Members
  • PipPip
  • 27 posts
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;
    }
}


#4
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
What's not working?

#5
adzeds

adzeds

    Newbie

  • Members
  • PipPip
  • 27 posts
The:
$keywords & $sedomain
variables seem to be returned blank!

How do I return more that one variable from a function?

#6
adzeds

adzeds

    Newbie

  • Members
  • PipPip
  • 27 posts
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?