Posted By

jamesming on 08/23/08


Tagged

google yahoo msn keyword referral referring


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

luman
jprice
vali29
Priestd09


Which Search Engine is referring users to your site. Displays the keyword used.


 / Published in: PHP
 

URL: http://www.webmasterworld.com/forum88/10984.htm

  1. if ((isset($_SERVER['HTTP_REFERER'])) and ($_SERVER['HTTP_REFERER']!= '')) {
  2. $keywords = "";
  3. $url = urldecode($_SERVER['HTTP_REFERER']);
  4.  
  5. // Google
  6. if (eregi("www\.google",$url)) {
  7. preg_match("'(\?¦&)q=(.*?)(&¦$)'si", " $url ", $keywords);
  8. $search_engine = 'Google';
  9. }
  10.  
  11. // Yahoo
  12. if ((eregi("yahoo\.com",$url)) or (eregi("search\.yahoo",$url))) {
  13. preg_match("'(\?¦&)p=(.*?)(&¦$)'si", " $url ", $keywords);
  14. $search_engine = 'Yahoo';
  15. }
  16.  
  17. // MSN
  18. if (eregi("search\.msn",$url)) {
  19. preg_match("'(\?¦&)q=(.*?)(&¦$)'si", " $url ", $keywords);
  20. $search_engine = 'MSN';
  21. }
  22.  
  23. // AllTheWeb
  24. if (eregi("www\.alltheweb",$url)) {
  25. preg_match("'(\?¦&)q=(.*?)(&¦$)'si", " $url ", $keywords);
  26. $search_engine = 'AllTheWeb';
  27. }
  28.  
  29. // Looksmart
  30. if (eregi("looksmart\.com",$url)) {
  31. preg_match("'(\?¦&)qt=(.*?)(&¦$)'si", " $url ", $keywords);
  32. $search_engine = 'Looksmart';
  33. }
  34.  
  35. if (($keywords[2]!= '') and ($keywords[2]!= ' ')) {
  36. $keywords = preg_replace('/"¦\'/', '', $keywords[2]); // Remove quotes
  37. }
  38. echo $keywords;
  39. echo $search_engine;
  40. }

Report this snippet  

You need to login to post a comment.