Como identificar o browser de seu visitante e decidir se é um dispositivo móvel How to identify the browser of your visitor and decide whether it is a mobile device
Escrito por Manoel Franklin em Setembro 12, 2008 Written by Manoel Franklin on September 12, 2008Aprenda a criar um blog acessível, crie uma versão ou uma funcionalidade especialmente para usuários mobile. Learn how to create a blog accessible, create a version or a feature especially for mobile users. Este tutorial lhe ensinará a descobrir se o browser do seu visitante é de um dispositivo mobile, experiemente! This tutorial will teach you how to find out if the browser your visitor is a mobile device, try it!
A web, assim como tudo hoje em dia, está ficando cada vez mais personalizada. The web, like everything else nowadays, is becoming more personalized. Hoje, a fatia de mercado composta por usuários (potenciais visitantes) que usam tecnologias mobile como celulares e PDAs cresce exponencialmente. Today, the market share made up of users (potential visitors) who use technologies such as mobile phones and PDAs is growing exponentially.
Identificar o browser de seus visitantes e adaptar o seu conteúdo a isto pode ser um grande trunfo para seu blog. Identify the browser of your visitors and to adapt the content of this can be a great asset to your blog. Dar este tipo de acessibilidade aos seus visitantes garante um nível de fidelidade impressionante. Giving this type of accessibility to visitors provides an impressive level of fidelity. O código fonte abaixo escrito em PHP pode fácilmente identificar o browser de seu visitante e decidir se ele é um visitante mobile ou não, daí pra frente, a sua criatividade é que manda. The source code below was written in PHP can easily identify the browser of your visitor and decide whether he is a visitor mobile or not, then do it, your creativity is king.
if ( if ( preg_match preg_match ( '/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i' , ( '/ (UP.Browser | UP.Link | mmp | symbian | smartphone | midp | wap | phone) / i',
strtolower strtolower ( $_SERVER [ 'HTTP_USER_AGENT' ] ) ) ) { ($ _SERVER [ 'HTTP_USER_AGENT']))) (
$mobile_browser ++; $ mobile_browser + +;
} )
if ( ( if (( strpos strpos ( ( strtolower strtolower ( $_SERVER [ 'HTTP_ACCEPT' ] ) , 'application/vnd.wap.xhtml+xml' ) > 0 ) or ($ _SERVER [ 'HTTP_ACCEPT']), 'application / vnd.wap.xhtml + xml')> 0) or
( ( (( isset isset ( $_SERVER [ 'HTTP_X_WAP_PROFILE' ] ) or ($ _SERVER [ 'HTTP_X_WAP_PROFILE']) or isset isset ( $_SERVER [ 'HTTP_PROFILE' ] ) ) ) ) { ($ _SERVER [ 'HTTP_PROFILE'])))) (
$mobile_browser ++; $ mobile_browser + +;
} )
$mobile_ua = $ mobile_ua = strtolower strtolower ( ( substr substr ( $_SERVER [ 'HTTP_USER_AGENT' ] , 0 , 4 ) ) ; ($ _SERVER [ 'HTTP_USER_AGENT'], 0, 4));
$mobile_agents = $ mobile_agents = array array ( (
'w3c ' , 'acs-' , 'alav' , 'alca' , 'amoi' , 'audi' , 'avan' , 'benq' , 'bird' , 'blac' , 'W3C', 'acs-', 'alav', 'arti', 'amoi', 'audi', 'advanced', 'benq', 'bird', 'blac',
'blaz' , 'brew' , 'cell' , 'cldc' , 'cmd-' , 'dang' , 'doco' , 'eric' , 'hipt' , 'inno' , 'Blaze', 'brew', 'cell', 'CLDC', 'cmd-', 'dang', 'doco', 'Eric', 'hipt', 'inno',
'ipaq' , 'java' , 'jigs' , 'kddi' , 'keji' , 'leno' , 'lg-c' , 'lg-d' , 'lg-g' , 'lge-' , 'ipaq', 'java', 'jigs', 'KDDI', 'Keji', 'leno', 'lg-c', 'lg-d', 'lg-g', 'lge-',
'maui' , 'maxo' , 'midp' , 'mits' , 'mmef' , 'mobi' , 'mot-' , 'moto' , 'mwbp' , 'nec-' , 'maui', 'maxo', 'midp', 'mits', 'mmef', 'mobi', 'mot-', 'moto', 'MWBP', 'nec-',
'newt' , 'noki' , 'oper' , 'palm' , 'pana' , 'pant' , 'phil' , 'play' , 'port' , 'prox' , 'newt', 'noki', 'oper', 'palm', 'pana', 'pant', 'phil', 'play', 'port', 'prox',
'qwap' , 'sage' , 'sams' , 'sany' , 'sch-' , 'sec-' , 'send' , 'seri' , 'sgh-' , 'shar' , 'qwap', 'sage', 'sams', 'sany', 'sch-', 'sec-', 'send', 'seri', 'SGH-', 'shar',
'sie-' , 'siem' , 'smal' , 'smar' , 'sony' , 'sph-' , 'symb' , 't-mo' , 'teli' , 'tim-' , 'sie-', 'siem', 'smal', 'smar', 'sony', 'sph-', 'symb', 't-mo', 'teli', 'tim-',
'tosh' , 'tsm-' , 'upg1′ , 'upsi' , 'vk-v' , 'voda' , 'wap-' , 'wapa' , 'wapi' , 'wapp' , 'tosh', 'tsm-', 'UPG1', 'upsi', 'vk-v', 'voda', 'wap-', 'wapa', 'wapi', 'WAPP',
'wapr' , 'webc' , 'winw' , 'winw' , 'xda' , 'xda-' ) ; 'wapr', 'webcam', 'winw', 'winw', 'xda', 'xda-');
if ( if ( in_array in_array ( $mobile_ua , $mobile_agents ) ) { ($ Mobile_ua, $ mobile_agents)) (
$mobile_browser ++; $ mobile_browser + +;
} )
if ( if ( strpos strpos ( ( strtolower strtolower ( $_SERVER [ 'ALL_HTTP' ] ) , 'OperaMini' ) > 0 ) { ($ _SERVER [ 'ALL_HTTP']), 'OperaMini')> 0) (
$mobile_browser ++; $ mobile_browser + +;
} )
if ( if ( strpos strpos ( ( strtolower strtolower ( $_SERVER [ 'HTTP_USER_AGENT' ] ) , 'windows' ) > 0 ) { ($ _SERVER [ 'HTTP_USER_AGENT']), 'windows')> 0) (
$mobile_browser = 0 ; $ mobile_browser = 0;
} )
if ( $mobile_browser > 0 ) { if ($ mobile_browser> 0) (
// do something / / Do something
} else { ) Else (
// do something else / / Do something else
} )
?> ?>
Aprendi isto aqui: I learned this here: http://dev.mobi/article/lightweight-device-detection-php http://dev.mobi/article/lightweight-device-detection-php
Espero que seja muito útil! I hope it's useful! Um grande abraço e até a próxima! A big hug and see you soon!
Postado em Posted Tutoriais Tutorials | | 2 Comentários » 2 Comments »

















Setembro 12th, 2008 em 14:27 September 12th, 2008 at 14:27
Muito interessante! Very interesting!
Abraços Hugs
Rodrigo Piva escreveu… Rodrigo Piva wrote ... Brasil é o 125º entre 181 países do ranking do Bird Brazil is the 125th among 181 countries in the ranking of the Bird
Abril 27th, 2009 em 16:39 April 27th, 2009 at 16:39
Nao consegui fazer funcionar… podes me ajudar? Not able to work ... can you help me?