Posted By

robksawyer on 08/05/09


Tagged

phone detection mobile cell iphone server-side


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

brent-man
umang_nine
fady_ay


Server-side mobile device detection


 / Published in: PHP
 

URL: http://www.phpdevblog.net/2009/01/detecting-mobile-devices.html

  1. class Client
  2. {
  3. /**
  4. * Available Mobile Clients
  5. *
  6. * @var array
  7. */
  8. private $_mobileClients = array(
  9. "midp",
  10. "240x320",
  11. "blackberry",
  12. "netfront",
  13. "nokia",
  14. "panasonic",
  15. "portalmmm",
  16. "sharp",
  17. "sie-",
  18. "sonyericsson",
  19. "symbian",
  20. "windows ce",
  21. "benq",
  22. "mda",
  23. "mot-",
  24. "opera mini",
  25. "philips",
  26. "pocket pc",
  27. "sagem",
  28. "samsung",
  29. "sda",
  30. "sgh-",
  31. "vodafone",
  32. "xda",
  33. "iphone",
  34. "android"
  35. );
  36.  
  37. /**
  38. * Check if client is a mobile client
  39. *
  40. * @param string $userAgent
  41. * @return boolean
  42. */
  43. public function isMobileClient($userAgent)
  44. {
  45. $userAgent = strtolower($userAgent);
  46. foreach($this->_mobileClients as $mobileClient) {
  47. if (strstr($userAgent, $mobileClient)) {
  48. return true;
  49. }
  50. }
  51. return false;
  52. }
  53.  
  54. }
  55.  
  56. $client = new Client();
  57. $client->isMobileClient($_SERVER['HTTP_USER_AGENT']);

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: ifuschini on September 30, 2009

Hi, there is a more sophisticated method to resolve mobile detection problem. It's call "Apache Mobile Filter", this filter allows you to access WURFL from any programming language, not just Java and php that is traditionally used for dynamic mobile web sites.

The module detects the mobile device and passes the WURFL capabilities on to the other web application as environment variables. It can also be used to resize images on the fly to adapt to the screen size of the mobile device.

For more info: http://www.idelfuschini.it/apache-mobile-filter-v2x.html

You need to login to post a comment.