Link to home
Start Free TrialLog in
Avatar of MayoorPatel
MayoorPatel

asked on

Detecting google in the referer

I have some code that grabs the referering pages referer url and parses it to detect whether it has the string google in it. However it doesnt seem to detect it. Can some look at my code and give a suggestion on how to make it better.


$referer = $_SERVER['HTTP_REFERER'];
 
  //Did they get here from a search?
  if((preg_match('/www\.google.*/i',$referer) && !preg_match('/^http:\/\/www\.google\.com\//i', $referer))
     || preg_match('/search\.atomz.*/i',$referer)
     || preg_match('/search\.msn.*/i',$referer)
     || preg_match('/search\.yahoo.*/i',$referer)
     || preg_match('/msxml\.excite\.com/i', $referer)
     || preg_match('/search\.lycos\.com/i', $referer)
     || preg_match('/www\.alltheweb\.com/i', $referer)
     || preg_match('/search\.aol\.com/i', $referer)
     || preg_match('/search\.iwon\.com/i', $referer)
     || preg_match('/ask\.com/i', $referer)
     || preg_match('/search\.cometsystems\.com/i', $referer)
     || preg_match('/www\.hotbot\.com/i', $referer)
     || preg_match('/www\.overture\.com/i', $referer)
     || preg_match('/www\.metacrawler\.com/i', $referer)
     || preg_match('/search\.netscape\.com/i', $referer)
     || preg_match('/www\.looksmart\.com/i', $referer)
     || preg_match('/go\.google\.com/i', $referer)
     || preg_match('/dpxml\.webcrawler\.com/i', $referer)
     || preg_match('/search\.earthlink\.net/i', $referer)
     || preg_match('/search\.viewpoint\.com/i', $referer)
     || preg_match('/www\.mamma\.com/i', $referer)
     || preg_match('/home\.bellsouth\.net\/s\/s\.dll/i', $referer)
     || preg_match('/www\.ask\.co\.uk/i', $referer)) {
 
Echo "Search Engine Detected";
 
}
 
Here is the value of the referer varibale.
 
http://www.google.com/search?client=safari&rls=en-us&q=Danbury+CT+chive&ie=UTF-8&oe=UTF-8

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Make a function with an array of the things you want to match.  I will post an example in  a few moments. ~Ray
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MayoorPatel
MayoorPatel

ASKER

Excellent
Thanks for the points!  It's a good question, ~Ray