Closed Thread
Results 1 to 6 of 6

Thread: PHP Web Analytics

  1. #1
    adzeds is offline Newbie
    Join Date
    Oct 2009
    Location
    Bristol, UK
    Posts
    27
    Rep Power
    0

    PHP Web Analytics

    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. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: PHP Web Analytics

    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

  4. #3
    adzeds is offline Newbie
    Join Date
    Oct 2009
    Location
    Bristol, UK
    Posts
    27
    Rep Power
    0

    Re: PHP Web Analytics

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

    Any ideas?

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


  5. #4
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    Re: PHP Web Analytics

    What's not working?

  6. #5
    adzeds is offline Newbie
    Join Date
    Oct 2009
    Location
    Bristol, UK
    Posts
    27
    Rep Power
    0

    Re: PHP Web Analytics

    The:
    $keywords & $sedomain
    variables seem to be returned blank!

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

  7. #6
    adzeds is offline Newbie
    Join Date
    Oct 2009
    Location
    Bristol, UK
    Posts
    27
    Rep Power
    0

    Re: PHP Web Analytics

    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?

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. PHP Web Analytics Script
    By adzeds in forum PHP Development
    Replies: 4
    Last Post: 10-25-2009, 04:42 AM
  2. Analytics Slow!!!!
    By NeedHelp in forum Marketing
    Replies: 1
    Last Post: 11-06-2006, 04:27 PM
  3. Google Analytics
    By Blaze in forum Marketing
    Replies: 8
    Last Post: 10-04-2006, 05:06 PM
  4. Google Analytics
    By Crane in forum Search Engine Optimization
    Replies: 15
    Last Post: 07-22-2006, 12:22 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts