Jump to content




Recent Status Updates

  • Photo
      15 Nov
    duzamucha

    Hi, I am final year Interior Design Student from University of Huddersfield. I am currently working on my final major project which is going to be linked to coding. I was hoping that you could help me with my research. I have prepared a short survey, it would be a massive help if you could fill it in for me. It takes less than 2 minutes to complete, I promise. Here is the link: https://www.surveymonkey.com/s/73XLJKK Thank you so much in advance!

View All Updates

Developed by TechBiz Xccelerator
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




Powered by binpress