detect referer is searchengine + keywords

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

detect referer is searchengine + keywords

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Are you trying to deny robots from spidering? This is usually done in the robots.txt file.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Your first question was already answered in your first post: viewtopic.php?t=60600
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

Post 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.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

my mistake -- sorry about that :oops:
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

Post by potato »

no prob :wink:
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

Post 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));

}}
Post Reply