Return to Snippet

Revision: 30471
at August 14, 2010 04:58 by 3k-


Updated Code
/**
 * Detects most mobile agents.
 * 
 * @return bool
 * @see http://en.wikipedia.org/wiki/List_of_user_agents_for_mobile_phones
 */
function isMobile()
{
  $userAgent = $_SERVER["HTTP_USER_AGENT"];
  $yes = strpos($userAgent, "Android") !== false;
  $yes = $yes || strpos($userAgent, "iPhone") !== false;
  $yes = $yes || strpos($userAgent, "Palm") !== false;
  $yes = $yes || strpos($userAgent, "Symbian") !== false;
  $yes = $yes || strpos($userAgent, "Mobile") !== false;
  $yes = $yes || strpos($userAgent, "MIDP") !== false;
  $yes = $yes || strpos($userAgent, "CLDC") !== false;
  return $yes;
}

Revision: 30470
at August 14, 2010 04:55 by 3k-


Initial Code
/**
 * Detects most mobile agents.
 * 
 * @return bool
 * @see http://en.wikipedia.org/wiki/List_of_user_agents_for_mobile_phones
 */
function isMobile()
{
  $yes = strpos($this->userAgent, "Android") !== false;
  $yes = $yes || strpos($this->userAgent, "iPhone") !== false;
  $yes = $yes || strpos($this->userAgent, "Palm") !== false;
  $yes = $yes || strpos($this->userAgent, "Symbian") !== false;
  $yes = $yes || strpos($this->userAgent, "Mobile") !== false;
  $yes = $yes || strpos($this->userAgent, "MIDP") !== false;
  $yes = $yes || strpos($this->userAgent, "CLDC") !== false;
  return $yes;
}

Initial URL


Initial Description


Initial Title
Detect most mobile HTTP clients

Initial Tags
http, mobile, web

Initial Language
PHP