Page 1 of 1

detect referer is searchengine + keywords

Posted: Mon Dec 11, 2006 1:35 pm
by potato
greetings,

i want to detect if the referer is a searchengine and if it is, detect the keywords out of it.
I've been googling for some time now for a compete function or something like that.

this ive got:

Code: Select all

$ref = parse_url($_SERVER['HTTP_REFERER']);
$referer = $ref['host']; 

if ($referer == "www.google.be"){$se = 1;}
but i dont want to make one line for each se + all the se from different countries.
Is there an easyer way to do this?

Posted: Mon Dec 11, 2006 1:53 pm
by John Cartwright
Are you trying to deny robots from spidering? This is usually done in the robots.txt file.

Posted: Mon Dec 11, 2006 1:56 pm
by aaronhall
Your first question was already answered in your first post: viewtopic.php?t=60600

Posted: Mon Dec 11, 2006 2:14 pm
by potato
nope, its totally different.
Their, i want to detect the crawl-bots, now i want to detect if a referer is a searchengine.
so if the visitor comes from a se.

Posted: Mon Dec 11, 2006 2:15 pm
by aaronhall
my mistake -- sorry about that :oops:

Posted: Mon Dec 11, 2006 2:22 pm
by potato
no prob :wink:

Posted: Mon Dec 11, 2006 2:53 pm
by potato
ok, i've got this:

Code: Select all

if ((!eregi("www\.bevibed\.be",$HTTP_REFERER)) and ($HTTP_REFERER!="")) { 

  $keywords="";

      // Google, AllTheWeb, MSN, Freeserve, Altavista 
	  if (eregi("www\.google",$url)) { preg_match("'q=(.*?)(&| )'si", " $url ", $keywords); $se = "Google";}
	  
	  if (eregi("www\.alltheweb",$url)) { preg_match("'q=(.*?)(&| )'si", " $url ", $keywords); $se = "Alltheweb";}
	  
	  if (eregi("search\.msn",$url)) { preg_match("'q=(.*?)(&| )'si", " $url ", $keywords); $se = "MSN";}
	  
	  if (eregi("ifind\.freeserve",$url)) { preg_match("'q=(.*?)(&| )'si", " $url ", $keywords); $se = "Ifind.Freeserve";}
	  
	  if (eregi("altavista\.com",$url)) { preg_match("'q=(.*?)(&| )'si", " $url ", $keywords); $se = "Altavista";} 

	  if (eregi("web\.ask",$url)) { preg_match("'q=(.*?)(&| )'si", " $url ", $keywords); $se = "Ask Jeeves";} 
	  
	  // HotBot, Lycos, Netscape, AOL 
      if (eregi("www\.hotbot",$url)) { preg_match("'query=(.*?)(&| )'si", " $url ", $keywords); $se = "Hotbot";}
	  
	  if (eregi("search\.lycos",$url)) { preg_match("'query=(.*?)(&| )'si", " $url ", $keywords); $se = "Lycos";}
	  
	  if (eregi("search\.netscape",$url)) { preg_match("'query=(.*?)(&| )'si", " $url ", $keywords); $se = "Search.Netscape";}
	  
	  if (eregi("aolsearch\.aol",$url)) { preg_match("'query=(.*?)(&| )'si", " $url ", $keywords); $se = "Aolsearch";} 
      
	  // Yahoo 
      if ((eregi("yahoo\.com",$url)) or (eregi("search\.yahoo",$url))) { preg_match("'p=(.*?)(&| )'si", " $url ", $keywords); $se = "Yahoo";} 
      
	  // Looksmart 
      if (eregi("looksmart\.com",$url)) { preg_match("'key=(.*?)(&| )'si", " $url ", $keywords); $se = "Looksmart";} 
      
	  // DMOZ 
      if (eregi("search\.dmoz",$url)) { preg_match("'search=(.*?)(&| )'si", " $url ", $keywords); $se = "Search.Dmoz";}
	   
      // Ask 
      if (eregi("ask\.co",$url)) { preg_match("'ask=(.*?)(&| )'si", " $url ", $keywords); $se="Ask.co";} 

if (($keywords[1]!="") and ($keywords[1]!=" ")) { 
         $keywords=preg_replace("/\+/"," ",$keywords[1]);    
         $keywords=eregi_replace("%2B"," ",$keywords); 
         $keywords=eregi_replace("%2E","\.",$keywords); 
         $keywords=trim(eregi_replace("%22","\"",$keywords));

}}