+ Reply to Thread
Results 1 to 6 of 6

Thread: PHP Web Analytics

  1. #1
    Newbie adzeds is an unknown quantity at this point
    Join Date
    Oct 2009
    Location
    Bristol, UK
    Posts
    27

    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. #2
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    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

  3. #3
    Newbie adzeds is an unknown quantity at this point
    Join Date
    Oct 2009
    Location
    Bristol, UK
    Posts
    27

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


  4. #4
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,883
    Blog Entries
    25

    Re: PHP Web Analytics

    What's not working?

  5. #5
    Newbie adzeds is an unknown quantity at this point
    Join Date
    Oct 2009
    Location
    Bristol, UK
    Posts
    27

    Re: PHP Web Analytics

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

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

  6. #6
    Newbie adzeds is an unknown quantity at this point
    Join Date
    Oct 2009
    Location
    Bristol, UK
    Posts
    27

    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?

+ Reply to 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 Forum
    Replies: 4
    Last Post: 10-25-2009, 06:42 AM
  2. PHP 5 and OOP
    By Jordan in forum PHP Tutorials
    Replies: 11
    Last Post: 09-22-2008, 01:58 AM
  3. PHP 4 end of life announcement
    By Jordan in forum News
    Replies: 4
    Last Post: 08-30-2007, 09:55 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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