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

<?php

class search_keywords
{
var $referer;

var $search_engine;

var $keys;

var $sep;

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

if ($_SERVER[‘HTTP_REFERER’] OR $_ENV[‘HTTP_REFERER’])
{
$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))
{

// MSN
preg_match(“#{$this->sep}q=(.*?)\&#si”, $this->referer, $this->keys);
$this->search_engine = ‘MSN’;
}
else if (eregi(‘www\.alltheweb’, $this->referer))
{
// AllTheWeb
preg_match(“#{$this->sep}q=(.*?)\&#si”, $this->referer, $this->keys);
$this->search_engine = ‘AllTheWeb’;
}
else if (eregi(‘(looksmart\.com|search\.looksmart)’, $this->referer))
{
// Looksmart
preg_match(“#{$this->sep}qt=(.*?)\&#si”, $this->referer, $this->keys);
$this->search_engine = ‘Looksmart’;
}
else if (eregi(‘(askjeeves\.com|ask\.com)’, $this->referer))
{
// AskJeeves
preg_match(“#{$this->sep}q=(.*?)\&#si”, $this->referer, $this->keys);
$this->search_engine = ‘AskJeeves’;
}
else
{
$this->keys = ‘Not available’;
$this->search_engine = ‘Unknown’;
}
return array(
$this->referer,
(!is_array($this->keys) ? $this->keys : $this->keys[1]),
$this->search_engine
);
}
return array();
}
}

?>

Now you have the classes, you can use this example PHP script to shown the result, save it as blabla.php $keys[3] will shown information about full referer URL so you can add or remove it.

<?php

require_once(‘./searchkeys.class.php’);

$keys =& new search_keywords();
$keys = $keys->get_keys();

if (count($keys))
{
echo “You’re directed to this page from <b>$keys[2]</b> search engine, within Keywords <b>’$keys[1]'</b>”;
}

?>

Now you can add this snippet to your page, The result is same like this screen shoot(blue box):

php-se-keyword-catch

Done, I hope someone would created WP plugins using this script and added some feature. That would be nice he he 🙂

Download the package here!

Similar Posts:

Related Search Terms:

  • php detectar referer adwords
  • php detectar referer adwords
  • google catch search words
  • google catch search words
  • get referer search key google php
  • capture search engine keywords in php
  • get referer search key google php
  • capture search engine keywords in php
  • detect search engine referral
  • detect search engine referral
  • getsearchenginekeywords
  • php google referrer key phrase
  • search keywords in php
  • php recognise adwords
  • save search keywords php
  • google adwords fetch referrer keyword
  • detect search engine keyowrds php
  • php capture search engine keywords
  • php parser google adwords keyword
  • extract referer keywords php google 2011
  • can save keyword in php
  • detecting adwords referers
  • php dÃtection keyword
  • how get search engine position from referer
  • php suchbegriffe aus referer ermitteln
  • vba parse google referrer strings
  • PHP: get keywords from search engine referer url
  • Bank Central Asia – Sector: Finance mail
  • php find keywords in string
  • getsearchenginekeywords
  • php recognise adwords
  • detect search engine keyowrds php
  • save search keywords php
  • google adwords fetch referrer keyword
  • search keywords in php
  • php google referrer key phrase
  • php find keywords in string
  • retrieve search keywords in asp
  • how get search engine position from referer
  • php capture search engine keywords
  • PHP: get keywords from search engine referer url
  • retrieve search keywords in asp
  • detect search engine referrer php
  • php parser google adwords keyword
  • extract referer keywords php google 2011
  • can save keyword in php
  • detecting adwords referers
  • php dÃtection keyword
  • php suchbegriffe aus referer ermitteln
  • vba parse google referrer strings
  • detect search engine referrer php
    Digg Del.icio.us StumbleUpon Reddit Twitter RSS

If you're new here, you may want to subscribe to my RSS feed. You may copy or publish this article to your blog or other site as long you give credit link back to this site article. Thanks for visiting my blog!