Return to Snippet

Revision: 16475
at August 5, 2009 20:27 by robksawyer


Initial Code
class Client
{
	/**
	 * Available Mobile Clients
	 *
	 * @var array
	 */
	private $_mobileClients = array(
		"midp",
		"240x320",
		"blackberry",
		"netfront",
		"nokia",
		"panasonic",
		"portalmmm",
		"sharp",
		"sie-",
		"sonyericsson",
		"symbian",
		"windows ce",
		"benq",
		"mda",
		"mot-",
		"opera mini",
		"philips",
		"pocket pc",
		"sagem",
		"samsung",
		"sda",
		"sgh-",
		"vodafone",
		"xda",
		"iphone",
		"android"
	);

	/**
	 * Check if client is a mobile client
	 *
	 * @param string $userAgent
	 * @return boolean
	 */
	public function isMobileClient($userAgent)
	{
		$userAgent = strtolower($userAgent);
		foreach($this->_mobileClients as $mobileClient) {
			if (strstr($userAgent, $mobileClient)) {
				return true;
			}
		}
		return false;
	}

}

$client = new Client();
$client->isMobileClient($_SERVER['HTTP_USER_AGENT']);

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

Initial Description

                                

Initial Title
Server-side mobile device detection

Initial Tags
phone, mobile, iphone

Initial Language
PHP