Wordpress Browser Detection Function


/ Published in: PHP
Save to your folder(s)

Place in your functions.php file and call it in your theme like this:


Copy this code and paste it in your HTML
  1. /*Browser Detect*/
  2. function browser_detect(){
  3. $ipod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
  4. $iphone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
  5. $firefox = stripos($_SERVER['HTTP_USER_AGENT'],"Firefox");
  6. $safari = stripos($_SERVER['HTTP_USER_AGENT'],"Safari");
  7. $ie = stripos($_SERVER['HTTP_USER_AGENT'],"MSIE");
  8. $opera = stripos($_SERVER['HTTP_USER_AGENT'],"Opera");
  9. $maxthon = stripos($_SERVER['HTTP_USER_AGENT'],"Maxthon");
  10. $chrome = stripos($_SERVER['HTTP_USER_AGENT'],"Chrome");
  11. $netscape = stripos($_SERVER['HTTP_USER_AGENT'],"Netscape");
  12. $traveler = stripos($_SERVER['HTTP_USER_AGENT'], "Traveler");
  13. //detecting device
  14. if ($ipod == true || $iphone == true){
  15. echo "<div class=\"browser\">";
  16. echo "<img src=\"images/iphone.png\">";
  17. echo "<br />";
  18. echo "<p>You are viewing this site on an Ipod or Iphone</p>";
  19. echo "</div>";
  20. }elseif($firefox == true){
  21. echo "<div class=\"browser\">";
  22. echo "<img src=\"images/Firefox.png\">";
  23. echo "<br />";
  24. echo "<p>You are viewing this site in Firefox</p>";
  25. echo "</div>";
  26.  
  27. }elseif($ie == true){
  28. echo "<div class=\"browser\">";
  29. echo "<img src=\"images/IE.png\">";
  30. echo "<br />";
  31. echo "<p>You are viewing this site in Internet Explorer</p>";
  32. echo "</div>";
  33.  
  34. }elseif($netscape == true){
  35. echo "<div class=\"browser\">";
  36. echo "<img src=\"images/Netcape.png\">";
  37. echo "<br />";
  38. echo "<p>You are viewing this site in Netscape</p>";
  39. echo "</div>";
  40.  
  41. }elseif($traveler == true){
  42. echo "<div class=\"browser\">";
  43. echo "<img src=\"images/Traveler.png\">";
  44. echo "<br />";
  45. echo "<p>You are viewing this site in Traveler</p>";
  46. echo "</div>";
  47.  
  48. }elseif($maxthon == true){
  49. echo "<div class=\"browser\">";
  50. echo "<img src=\"images/Maxthon.png\">";
  51. echo "<br />";
  52. echo "<p>You are viewing this site in Maxthon</p>";
  53. echo "</div>";
  54.  
  55. }elseif($chrome == true){
  56. echo "<div class=\"browser\">";
  57. echo "<img src=\"images/Chrome.png\">";
  58. echo "<br />";
  59. echo "<p>You are viewing this site in Chrome</p>";
  60. echo "</div>";
  61.  
  62. }elseif($safari == true){
  63. echo "<div class=\"browser\">";
  64. echo "<img src=\"images/Safari.png\">";
  65. echo "<br />";
  66. echo "<p>You are viewing this site in Safari</p>";
  67. echo "</div>";
  68.  
  69. }elseif($opera == true){
  70. echo "<div class=\"browser\">";
  71. echo "<img src=\"images/Opera.png\">";
  72. echo "<br />";
  73. echo "<p>You are viewing this site in Opera</p>";
  74. echo "</div>";
  75. }else{
  76. echo "<div class=\"browser\">";
  77. echo "<img src=\"images/Q.png\">";
  78. echo "<br />";
  79. echo "<p>We currently dont know your browser.</p>";
  80. echo "</div>";
  81. }
  82. };

URL: http://afj176.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.