Posted By

3k- on 08/14/10


Tagged

http mobile web useragent


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

convergine
d55beck


Detect most mobile HTTP clients


 / Published in: PHP
 

  1. /**
  2.  * Detects most mobile agents.
  3.  *
  4.  * @return bool
  5.  * @see http://en.wikipedia.org/wiki/List_of_user_agents_for_mobile_phones
  6.  */
  7. function isMobile()
  8. {
  9. $userAgent = $_SERVER["HTTP_USER_AGENT"];
  10. $yes = strpos($userAgent, "Android") !== false;
  11. $yes = $yes || strpos($userAgent, "iPhone") !== false;
  12. $yes = $yes || strpos($userAgent, "Palm") !== false;
  13. $yes = $yes || strpos($userAgent, "Symbian") !== false;
  14. $yes = $yes || strpos($userAgent, "Mobile") !== false;
  15. $yes = $yes || strpos($userAgent, "MIDP") !== false;
  16. $yes = $yes || strpos($userAgent, "CLDC") !== false;
  17. return $yes;
  18. }

Report this snippet  

You need to login to post a comment.