Ловим мобильных клиентов


PHP-класс, который позволит определить факт захода на Ваш сайт с мобильного телефона.

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();
$isMobileClient = $client->isMobileClient($_SERVER['HTTP_USER_AGENT']);

Поблагодарить автора

4 Responses to Ловим мобильных клиентов

  1. Стыдно признаться, но я не знала, что для фиксации захода на сайт мобильных клиентов нужно что-то делать. Думала, что они идут наравне с остальными.

  2. Да, по умолчанию они идут наравне со всеми, но логичным будет отдавать им не полную версию сайта, а к примеру с облегченным дизайном.

Оставить комментарий

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>