Detect most mobile HTTP clients


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



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.