php script to catch keyword.referer information

PHP:Catching keyword from search engine

Good day everyone, In this article we will learn how to catch information from “HTTP_REFERER” function such as, referer info, keyword info, etc. From some search engine using PHP snippet. This script might usefully when you want to analyze your keyword and referer statistic. Last night I was searching in WP plugin for this script but I didn’t found one really good.

So let’s created it our self, First, You need this PHP class save it as searchkeys.class.php


class search_keywords
var $referer;

var $search_engine;

var $keys;

var $sep;

function search_keywords()
$this->referer = ”;
$this->sep = ”;

$this->referer = urldecode(($_SERVER[‘HTTP_REFERER’] ? $_SERVER[‘HTTP_REFERER’] : $_ENV[‘HTTP_REFERER’]));
$this->sep = (eregi(‘(\?q=|\?qt=|\?p=)’, $this->referer)) ? ‘\?’ : ‘\&’;

function get_keys()
if (!empty($this->referer))
if (eregi(‘www\.google’, $this->referer))
// Google
preg_match(“#{$this->sep}q=(.*?)\&#si”, $this->referer, $this->keys);
$this->search_engine = ‘Google’;
else if (eregi(‘(yahoo\.com|search\.yahoo)’, $this->referer))
// Yahoo
preg_match(“#{$this->sep}p=(.*?)\&#si”, $this->referer, $this->keys);
$this->search_engine = ‘Yahoo’;
else if (eregi(‘search\.msn’, $this->referer))
Read More »PHP:Catching keyword from search engine