Get Keyword from referrer

This Function should extract the keyword from the referrer URL to get what your visitor was searching for on google, msn, live, altavista, alltheweb, scirus, aol, vivisimo, lycos, aliweb, yahoo and baidu.

  1.  
  2. function getKeywordfromRef($orgWord){
  3.         $ref = $_SERVER['HTTP_REFERER'];
  4.         if( preg_match("#(google|msn|live|altavista|alltheweb|scirus)#si", $ref)){
  5.                 $s=explode("?",$ref);
  6.                 parse_str($s[1]);
  7.                 return $q;
  8.         }elseif(preg_match("#(aol|vivisimo|lycos|aliweb)#si", $ref) ){
  9.                 $s=explode("?",$ref);
  10.                 parse_str($s[1]);
  11.                 return $query;
  12.         }elseif(strstr( $ref,'yahoo')){
  13.                 $s=explode("?",$ref);
  14.                 parse_str($s[1]);
  15.                 return $p;
  16.         }elseif(strstr( $ref,'baidu')){
  17.                 $s=explode("?",$ref);
  18.                 parse_str($s[1]);
  19.                 return $wd;
  20.         }else
  21.                 return $orgWord;
  22. }
  23.  

you can send a default keyword in case the visitor was not coming from a search engine or just set $orgWord = ”
to call the function

  1.  
  2. $myKeyword = getKeywordfromRef($myKeyword)
  3.  

Tags :

This entry was posted on Sunday, November 26th, 2006 at 5:09 am and is filed under Blog, Solutions. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

 

Leave a Reply


 Top