Foros del Web » Programando para Internet » PHP »

Detectar dispositivo móvil

Estas en el tema de Detectar dispositivo móvil en el foro de PHP en Foros del Web. Hola, Estoy buscando la forma de detectar dispositivos móviles y quería si es posible la opinión de alguien que lo halla realizado, he buscado por ...
  #1 (permalink)  
Antiguo 25/05/2012, 12:43
Avatar de J_de_Prado  
Fecha de Ingreso: junio-2011
Ubicación: Alpedrete, Madrid,España
Mensajes: 28
Antigüedad: 12 años, 10 meses
Puntos: 2
Detectar dispositivo móvil

Hola,

Estoy buscando la forma de detectar dispositivos móviles y quería si es posible la opinión de alguien que lo halla realizado, he buscado por ahí con la frase:
"detectar dispositivo móvil en php" básicamente y lo que se encuentra es esto:

Código PHP:
Ver original
  1. <?php
  2. $mobile_browser = '0';
  3.  
  4. //$_SERVER['HTTP_USER_AGENT'] -> el agente de usuario que está accediendo a la página.
  5. //preg_match -> Realizar una comparación de expresión regular
  6.  
  7. if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i',strtolower($_SERVER['HTTP_USER_AGENT']))){
  8.     $mobile_browser++;
  9. }
  10.  
  11. //$_SERVER['HTTP_ACCEPT'] -> Indica los tipos MIME que el cliente puede recibir.
  12. if((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or
  13.     ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))){
  14.     $mobile_browser++;
  15. }
  16.  
  17. $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
  18. $mobile_agents = array(
  19.     'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
  20.     'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
  21.     'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
  22.     'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
  23.     'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
  24.     'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
  25.     'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
  26.     'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
  27.     'wapr','webc','winw','winw','xda','xda-');
  28.  
  29. //buscar agentes en el array de agentes
  30. if(in_array($mobile_ua,$mobile_agents)){
  31.     $mobile_browser++;
  32. }
  33.  
  34. //$_SERVER['ALL_HTTP'] -> Todas las cabeceras HTTP
  35. //strpos -> Primera aparicion de una cadena dentro de otra
  36. if(strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini')>0) {
  37.     $mobile_browser++;
  38. }
  39. if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) {
  40.     $mobile_browser=0;
  41. }
  42.  
  43. if($mobile_browser>0){
  44.         // Mostrar contenido para dispositivos móviles
  45.         // Estos pueden ser más ligeros: un titulo, resumen y algunos enlaces.
  46.         // Aca puede redirigir a la ruta donde este el contenido para moviles
  47.         // Por ejemplo: http://miweb.com/movil ó http://movil.miweb.com
  48.     echo 'hola navegador cell phone';
  49. }else{
  50.         // Contenido que se puede apreciar en navegadores de escritorio
  51.         echo 'hola navegador normal';
  52. }
  53. ?>



También he visto que [URL="http://mobiforge.com/developing/story/introduction-wurfl"]Aquí[/URL] hay otra forma de hacerlo parece que utilizan una base de datos que supongo iran actualizando…

¿Alguien puede aclarar algo que nos pueda servir a los demás?
  #2 (permalink)  
Antiguo 25/05/2012, 12:53
Avatar de skiper0125  
Fecha de Ingreso: octubre-2010
Ubicación: $this->Mexico('Toluca');
Mensajes: 1.127
Antigüedad: 13 años, 6 meses
Puntos: 511
Respuesta: Detectar dispositivo móvil

Cita:
Iniciado por J_de_Prado Ver Mensaje
Hola,

Estoy buscando la forma de detectar dispositivos móviles y quería si es posible la opinión de alguien que lo halla realizado, he buscado por ahí con la frase:
"detectar dispositivo móvil en php" básicamente y lo que se encuentra es esto ..............


¿Alguien puede aclarar algo que nos pueda servir a los demás?
Lamentablemente en PHP solo cuentas con las funciones que encontraste en el ejemplo($_SERVER) para detectar si el dispositivo es móvil o no, existen otras formas para saber que dispositivos esta visualizando nuestra página como podría ser javascript.

¿Para que deseas saber el tipo de dispositivo con PHP?

Saluos
__________________
Recuerda que estamos aquí para orientarte, y no para hacer tu trabajo.
Si mi aporte fue de ayuda, recuerda que agradecer no cuesta nada +1

Skiper0125
  #3 (permalink)  
Antiguo 25/05/2012, 12:55
Avatar de newboy_master  
Fecha de Ingreso: enero-2008
Ubicación: Granada
Mensajes: 882
Antigüedad: 16 años, 3 meses
Puntos: 46
Respuesta: Detectar dispositivo móvil

Prueba aquí:

http://detectmobilebrowsers.com/

La versión en PHP simplemente tiene un condicional, si se verifica te redirecciona a una página, donde supuestamente tendrás la versión móvil.

Salu2.
__________________
@jslirola - Programador Web Freelance.
  #4 (permalink)  
Antiguo 25/05/2012, 12:59
 
Fecha de Ingreso: enero-2011
Ubicación: /root
Mensajes: 530
Antigüedad: 13 años, 3 meses
Puntos: 61
Respuesta: Detectar dispositivo móvil

Esta funcion te podria servir .

Código PHP:
Ver original
  1. <?php
  2. function mobile_device_detect($iphone=true,$ipad=true,$android=true,$opera=true,$blackberry=true,$palm=true,$windows=true,$mobileredirect=false,$desktopredirect=false){
  3.        
  4.       $mobile_browser   = false; // set mobile browser as false till we can prove otherwise
  5.       $user_agent       = $_SERVER['HTTP_USER_AGENT']; // get the user agent value - this should be cleaned to ensure no nefarious input gets executed
  6.       $accept           = $_SERVER['HTTP_ACCEPT']; // get the content accept value - this should be cleaned to ensure no nefarious input gets executed
  7.    
  8.       switch(true){ // using a switch against the following statements which could return true is more efficient than the previous method of using if statements
  9.    
  10.         case (preg_match('/ipad/i',$user_agent)); // we find the word ipad in the user agent
  11.           $mobile_browser = $ipad; // mobile browser is either true or false depending on the setting of ipad when calling the function
  12.           $status = 'Apple iPad';
  13.           if(substr($ipad,0,4)=='http'){ // does the value of ipad resemble a url
  14.             $mobileredirect = $ipad; // set the mobile redirect url to the url value stored in the ipad value
  15.           } // ends the if for ipad being a url
  16.         break; // break out and skip the rest if we've had a match on the ipad // this goes before the iphone to catch it else it would return on the iphone instead
  17.    
  18.         case (preg_match('/ipod/i',$user_agent)||preg_match('/iphone/i',$user_agent)); // we find the words iphone or ipod in the user agent
  19.           $mobile_browser = $iphone; // mobile browser is either true or false depending on the setting of iphone when calling the function
  20.           $status = 'Apple';
  21.           if(substr($iphone,0,4)=='http'){ // does the value of iphone resemble a url
  22.             $mobileredirect = $iphone; // set the mobile redirect url to the url value stored in the iphone value
  23.           } // ends the if for iphone being a url
  24.         break; // break out and skip the rest if we've had a match on the iphone or ipod
  25.    
  26.         case (preg_match('/android/i',$user_agent));  // we find android in the user agent
  27.           $mobile_browser = $android; // mobile browser is either true or false depending on the setting of android when calling the function
  28.           $status = 'Android';
  29.           if(substr($android,0,4)=='http'){ // does the value of android resemble a url
  30.             $mobileredirect = $android; // set the mobile redirect url to the url value stored in the android value
  31.           } // ends the if for android being a url
  32.         break; // break out and skip the rest if we've had a match on android
  33.    
  34.         case (preg_match('/opera mini/i',$user_agent)); // we find opera mini in the user agent
  35.           $mobile_browser = $opera; // mobile browser is either true or false depending on the setting of opera when calling the function
  36.           $status = 'Opera';
  37.           if(substr($opera,0,4)=='http'){ // does the value of opera resemble a rul
  38.             $mobileredirect = $opera; // set the mobile redirect url to the url value stored in the opera value
  39.           } // ends the if for opera being a url
  40.         break; // break out and skip the rest if we've had a match on opera
  41.    
  42.         case (preg_match('/blackberry/i',$user_agent)); // we find blackberry in the user agent
  43.           $mobile_browser = $blackberry; // mobile browser is either true or false depending on the setting of blackberry when calling the function
  44.           $status = 'Blackberry';
  45.           if(substr($blackberry,0,4)=='http'){ // does the value of blackberry resemble a rul
  46.             $mobileredirect = $blackberry; // set the mobile redirect url to the url value stored in the blackberry value
  47.           } // ends the if for blackberry being a url
  48.         break; // break out and skip the rest if we've had a match on blackberry
  49.    
  50.         case (preg_match('/(pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine)/i',$user_agent)); // we find palm os in the user agent - the i at the end makes it case insensitive
  51.           $mobile_browser = $palm; // mobile browser is either true or false depending on the setting of palm when calling the function
  52.           $status = 'Palm';
  53.           if(substr($palm,0,4)=='http'){ // does the value of palm resemble a rul
  54.             $mobileredirect = $palm; // set the mobile redirect url to the url value stored in the palm value
  55.           } // ends the if for palm being a url
  56.         break; // break out and skip the rest if we've had a match on palm os
  57.    
  58.         case (preg_match('/(iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile)/i',$user_agent)); // we find windows mobile in the user agent - the i at the end makes it case insensitive
  59.           $mobile_browser = $windows; // mobile browser is either true or false depending on the setting of windows when calling the function
  60.           $status = 'Windows Smartphone';
  61.           if(substr($windows,0,4)=='http'){ // does the value of windows resemble a rul
  62.             $mobileredirect = $windows; // set the mobile redirect url to the url value stored in the windows value
  63.           } // ends the if for windows being a url
  64.         break; // break out and skip the rest if we've had a match on windows
  65.    
  66.         case (preg_match('/(mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320|vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo)/i',$user_agent)); // check if any of the values listed create a match on the user agent - these are some of the most common terms used in agents to identify them as being mobile devices - the i at the end makes it case insensitive
  67.           $mobile_browser = true; // set mobile browser to true
  68.           $status = 'Mobile matched on piped preg_match';
  69.         break; // break out and skip the rest if we've preg_match on the user agent returned true
  70.    
  71.         case ((strpos($accept,'text/vnd.wap.wml')>0)||(strpos($accept,'application/vnd.wap.xhtml+xml')>0)); // is the device showing signs of support for text/vnd.wap.wml or application/vnd.wap.xhtml+xml
  72.  
  73.           $mobile_browser = true; // set mobile browser to true
  74.           $status = 'Mobile matched on content accept header';
  75.         break; // break out and skip the rest if we've had a match on the content accept headers
  76.    
  77.         case (isset($_SERVER['HTTP_X_WAP_PROFILE'])||isset($_SERVER['HTTP_PROFILE'])); // is the device giving us a HTTP_X_WAP_PROFILE or HTTP_PROFILE header - only mobile devices would do this
  78.           $mobile_browser = true; // set mobile browser to true
  79.           $status = 'Mobile matched on profile headers being set';
  80.         break; // break out and skip the final step if we've had a return true on the mobile specfic headers
  81.  
  82.    
  83.     ?>


Saludos
  #5 (permalink)  
Antiguo 25/05/2012, 13:00
 
Fecha de Ingreso: enero-2011
Ubicación: /root
Mensajes: 530
Antigüedad: 13 años, 3 meses
Puntos: 61
Respuesta: Detectar dispositivo móvil

parte 2


Código PHP:
Ver original
  1. case (in_array(strtolower(substr($user_agent,0,4)),array('1207'=>'1207','3gso'=>'3gso','4thp'=>'4thp','501i'=>'501i','502i'=>'502i','503i'=>'503i','504i'=>'504i','505i'=>'505i','506i'=>'506i','6310'=>'6310','6590'=>'6590','770s'=>'770s','802s'=>'802s','a wa'=>'a wa','acer'=>'acer','acs-'=>'acs-','airn'=>'airn','alav'=>'alav','asus'=>'asus','attw'=>'attw','au-m'=>'au-m','aur '=>'aur ','aus '=>'aus ','abac'=>'abac','acoo'=>'acoo','aiko'=>'aiko','alco'=>'alco','alca'=>'alca','amoi'=>'amoi','anex'=>'anex','anny'=>'anny','anyw'=>'anyw','aptu'=>'aptu','arch'=>'arch','argo'=>'argo','bell'=>'bell','bird'=>'bird','bw-n'=>'bw-n','bw-u'=>'bw-u','beck'=>'beck','benq'=>'benq','bilb'=>'bilb','blac'=>'blac','c55/'=>'c55/','cdm-'=>'cdm-','chtm'=>'chtm','capi'=>'capi','cond'=>'cond','craw'=>'craw','dall'=>'dall','dbte'=>'dbte','dc-s'=>'dc-s','dica'=>'dica','ds-d'=>'ds-d','ds12'=>'ds12','dait'=>'dait','devi'=>'devi','dmob'=>'dmob','doco'=>'doco','dopo'=>'dopo','el49'=>'el49','erk0'=>'erk0','esl8'=>'esl8','ez40'=>'ez40','ez60'=>'ez60','ez70'=>'ez70','ezos'=>'ezos','ezze'=>'ezze','elai'=>'elai','emul'=>'emul','eric'=>'eric','ezwa'=>'ezwa','fake'=>'fake','fly-'=>'fly-','fly_'=>'fly_','g-mo'=>'g-mo','g1 u'=>'g1 u','g560'=>'g560','gf-5'=>'gf-5','grun'=>'grun','gene'=>'gene','go.w'=>'go.w','good'=>'good','grad'=>'grad','hcit'=>'hcit','hd-m'=>'hd-m','hd-p'=>'hd-p','hd-t'=>'hd-t','hei-'=>'hei-','hp i'=>'hp i','hpip'=>'hpip','hs-c'=>'hs-c','htc '=>'htc ','htc-'=>'htc-','htca'=>'htca','htcg'=>'htcg','htcp'=>'htcp','htcs'=>'htcs','htct'=>'htct','htc_'=>'htc_','haie'=>'haie','hita'=>'hita','huaw'=>'huaw','hutc'=>'hutc','i-20'=>'i-20','i-go'=>'i-go','i-ma'=>'i-ma','i230'=>'i230','iac'=>'iac','iac-'=>'iac-','iac/'=>'iac/','ig01'=>'ig01','im1k'=>'im1k','inno'=>'inno','iris'=>'iris','jata'=>'jata','java'=>'java','kddi'=>'kddi','kgt'=>'kgt','kgt/'=>'kgt/','kpt '=>'kpt ','kwc-'=>'kwc-','klon'=>'klon','lexi'=>'lexi','lg g'=>'lg g','lg-a'=>'lg-a','lg-b'=>'lg-b','lg-c'=>'lg-c','lg-d'=>'lg-d','lg-f'=>'lg-f','lg-g'=>'lg-g','lg-k'=>'lg-k','lg-l'=>'lg-l','lg-m'=>'lg-m','lg-o'=>'lg-o','lg-p'=>'lg-p','lg-s'=>'lg-s','lg-t'=>'lg-t','lg-u'=>'lg-u','lg-w'=>'lg-w','lg/k'=>'lg/k','lg/l'=>'lg/l','lg/u'=>'lg/u','lg50'=>'lg50','lg54'=>'lg54','lge-'=>'lge-','lge/'=>'lge/','lynx'=>'lynx','leno'=>'leno','m1-w'=>'m1-w','m3ga'=>'m3ga','m50/'=>'m50/','maui'=>'maui','mc01'=>'mc01','mc21'=>'mc21','mcca'=>'mcca','medi'=>'medi','meri'=>'meri','mio8'=>'mio8','mioa'=>'mioa','mo01'=>'mo01','mo02'=>'mo02','mode'=>'mode','modo'=>'modo','mot '=>'mot ','mot-'=>'mot-','mt50'=>'mt50','mtp1'=>'mtp1','mtv '=>'mtv ','mate'=>'mate','maxo'=>'maxo','merc'=>'merc','mits'=>'mits','mobi'=>'mobi','motv'=>'motv','mozz'=>'mozz','n100'=>'n100','n101'=>'n101','n102'=>'n102','n202'=>'n202','n203'=>'n203','n300'=>'n300','n302'=>'n302','n500'=>'n500','n502'=>'n502','n505'=>'n505','n700'=>'n700','n701'=>'n701','n710'=>'n710','nec-'=>'nec-','nem-'=>'nem-','newg'=>'newg','neon'=>'neon','netf'=>'netf','noki'=>'noki','nzph'=>'nzph','o2 x'=>'o2 x','o2-x'=>'o2-x','opwv'=>'opwv','owg1'=>'owg1','opti'=>'opti','oran'=>'oran','p800'=>'p800','pand'=>'pand','pg-1'=>'pg-1','pg-2'=>'pg-2','pg-3'=>'pg-3','pg-6'=>'pg-6','pg-8'=>'pg-8','pg-c'=>'pg-c','pg13'=>'pg13','phil'=>'phil','pn-2'=>'pn-2','pt-g'=>'pt-g','palm'=>'palm','pana'=>'pana','pire'=>'pire','pock'=>'pock','pose'=>'pose','psio'=>'psio','qa-a'=>'qa-a','qc-2'=>'qc-2','qc-3'=>'qc-3','qc-5'=>'qc-5','qc-7'=>'qc-7','qc07'=>'qc07','qc12'=>'qc12','qc21'=>'qc21','qc32'=>'qc32','qc60'=>'qc60','qci-'=>'qci-','qwap'=>'qwap','qtek'=>'qtek','r380'=>'r380','r600'=>'r600','raks'=>'raks','rim9'=>'rim9','rove'=>'rove','s55/'=>'s55/','sage'=>'sage','sams'=>'sams','sc01'=>'sc01','sch-'=>'sch-','scp-'=>'scp-','sdk/'=>'sdk/','se47'=>'se47','sec-'=>'sec-','sec0'=>'sec0','sec1'=>'sec1','semc'=>'semc','sgh-'=>'sgh-','shar'=>'shar','sie-'=>'sie-','sk-0'=>'sk-0','sl45'=>'sl45','slid'=>'slid','smb3'=>'smb3','smt5'=>'smt5','sp01'=>'sp01','sph-'=>'sph-','spv '=>'spv ','spv-'=>'spv-','sy01'=>'sy01','samm'=>'samm','sany'=>'sany','sava'=>'sava','scoo'=>'scoo','send'=>'send','siem'=>'siem','smar'=>'smar','smit'=>'smit','soft'=>'soft','sony'=>'sony','t-mo'=>'t-mo','t218'=>'t218','t250'=>'t250','t600'=>'t600','t610'=>'t610','t618'=>'t618','tcl-'=>'tcl-','tdg-'=>'tdg-','telm'=>'telm','tim-'=>'tim-','ts70'=>'ts70','tsm-'=>'tsm-','tsm3'=>'tsm3','tsm5'=>'tsm5','tx-9'=>'tx-9','tagt'=>'tagt','talk'=>'talk','teli'=>'teli','topl'=>'topl','hiba'=>'hiba','up.b'=>'up.b','upg1'=>'upg1','utst'=>'utst','v400'=>'v400','v750'=>'v750','veri'=>'veri','vk-v'=>'vk-v','vk40'=>'vk40','vk50'=>'vk50','vk52'=>'vk52','vk53'=>'vk53','vm40'=>'vm40','vx98'=>'vx98','virg'=>'virg','vite'=>'vite','voda'=>'voda','vulc'=>'vulc','w3c '=>'w3c ','w3c-'=>'w3c-','wapj'=>'wapj','wapp'=>'wapp','wapu'=>'wapu','wapm'=>'wapm','wig '=>'wig ','wapi'=>'wapi','wapr'=>'wapr','wapv'=>'wapv','wapy'=>'wapy','wapa'=>'wapa','waps'=>'waps','wapt'=>'wapt','winc'=>'winc','winw'=>'winw','wonu'=>'wonu','x700'=>'x700','xda2'=>'xda2','xdag'=>'xdag','yas-'=>'yas-','your'=>'your','zte-'=>'zte-','zeto'=>'zeto','acs-'=>'acs-','alav'=>'alav','alca'=>'alca','amoi'=>'amoi','aste'=>'aste','audi'=>'audi','avan'=>'avan','benq'=>'benq','bird'=>'bird','blac'=>'blac','blaz'=>'blaz','brew'=>'brew','brvw'=>'brvw','bumb'=>'bumb','ccwa'=>'ccwa','cell'=>'cell','cldc'=>'cldc','cmd-'=>'cmd-','dang'=>'dang','doco'=>'doco','eml2'=>'eml2','eric'=>'eric','fetc'=>'fetc','hipt'=>'hipt','http'=>'http','ibro'=>'ibro','idea'=>'idea','ikom'=>'ikom','inno'=>'inno','ipaq'=>'ipaq','jbro'=>'jbro','jemu'=>'jemu','java'=>'java','jigs'=>'jigs','kddi'=>'kddi','keji'=>'keji','kyoc'=>'kyoc','kyok'=>'kyok','leno'=>'leno','lg-c'=>'lg-c','lg-d'=>'lg-d','lg-g'=>'lg-g','lge-'=>'lge-','libw'=>'libw','m-cr'=>'m-cr','maui'=>'maui','maxo'=>'maxo','midp'=>'midp','mits'=>'mits','mmef'=>'mmef','mobi'=>'mobi','mot-'=>'mot-','moto'=>'moto','mwbp'=>'mwbp','mywa'=>'mywa','nec-'=>'nec-','newt'=>'newt','nok6'=>'nok6','noki'=>'noki','o2im'=>'o2im','opwv'=>'opwv','palm'=>'palm','pana'=>'pana','pant'=>'pant','pdxg'=>'pdxg','phil'=>'phil','play'=>'play','pluc'=>'pluc','port'=>'port','prox'=>'prox','qtek'=>'qtek','qwap'=>'qwap','rozo'=>'rozo','sage'=>'sage','sama'=>'sama','sams'=>'sams','sany'=>'sany','sch-'=>'sch-','sec-'=>'sec-','send'=>'send','seri'=>'seri','sgh-'=>'sgh-','shar'=>'shar','sie-'=>'sie-','siem'=>'siem','smal'=>'smal','smar'=>'smar','sony'=>'sony','sph-'=>'sph-','symb'=>'symb','t-mo'=>'t-mo','teli'=>'teli','tim-'=>'tim-','tosh'=>'tosh','treo'=>'treo','tsm-'=>'tsm-','upg1'=>'upg1','upsi'=>'upsi','vk-v'=>'vk-v','voda'=>'voda','vx52'=>'vx52','vx53'=>'vx53','vx60'=>'vx60','vx61'=>'vx61','vx70'=>'vx70','vx80'=>'vx80','vx81'=>'vx81','vx83'=>'vx83','vx85'=>'vx85','wap-'=>'wap-','wapa'=>'wapa','wapi'=>'wapi','wapp'=>'wapp','wapr'=>'wapr','webc'=>'webc','whit'=>'whit','winw'=>'winw','wmlb'=>'wmlb','xda-'=>'xda-',))); // check against a list of trimmed user agents to see if we find a match
  2.           $mobile_browser = true; // set mobile browser to true
  3.           $status = 'Mobile matched on in_array';
  4.         break; // break even though it's the last statement in the switch so there's nothing to break away from but it seems better to include it than exclude it
  5.    
  6.         default;
  7.           $mobile_browser = false; // set mobile browser to false
  8.           $status = 'Desktop / full capability browser';
  9.         break; // break even though it's the last statement in the switch so there's nothing to break away from but it seems better to include it than exclude it
  10.    
  11.       } // ends the switch
  12.    
  13.       // tell adaptation services (transcoders and proxies) to not alter the content based on user agent as it's already being managed by this script, some of them suck though and will disregard this....
  14.             // header('Cache-Control: no-transform'); // http://mobiforge.com/developing/story/setting-http-headers-advise-transcoding-proxies
  15.             // header('Vary: User-Agent, Accept'); // http://mobiforge.com/developing/story/setting-http-headers-advise-transcoding-proxies
  16.    
  17.       // if redirect (either the value of the mobile or desktop redirect depending on the value of $mobile_browser) is true redirect else we return the status of $mobile_browser
  18.       if($redirect = ($mobile_browser==true) ? $mobileredirect : $desktopredirect){
  19.         header('Location: '.$redirect); // redirect to the right url for this device
  20.         exit;
  21.       }else{
  22.                 // a couple of folkas have asked about the status - that's there to help you debug and understand what the script is doing
  23.                     if($mobile_browser==''){
  24.                             return $mobile_browser; // will return either true or false
  25.                     }else{
  26.                             return array($mobile_browser,$status); // is a mobile so we are returning an array ['0'] is true ['1'] is the $status value
  27.                     }
  28.             }
  29.    
  30.     } // ends function mobile_device_detect
  #6 (permalink)  
Antiguo 25/05/2012, 13:05
Avatar de skiper0125  
Fecha de Ingreso: octubre-2010
Ubicación: $this->Mexico('Toluca');
Mensajes: 1.127
Antigüedad: 13 años, 6 meses
Puntos: 511
Respuesta: Detectar dispositivo móvil

Cita:
Iniciado por newboy_master Ver Mensaje
Prueba aquí:

http://detectmobilebrowsers.com/

La versión en PHP simplemente tiene un condicional, si se verifica te redirecciona a una página, donde supuestamente tendrás la versión móvil.

Salu2.
Buena función no tiene mucho código
__________________
Recuerda que estamos aquí para orientarte, y no para hacer tu trabajo.
Si mi aporte fue de ayuda, recuerda que agradecer no cuesta nada +1

Skiper0125
  #7 (permalink)  
Antiguo 28/05/2012, 05:19
Avatar de J_de_Prado  
Fecha de Ingreso: junio-2011
Ubicación: Alpedrete, Madrid,España
Mensajes: 28
Antigüedad: 12 años, 10 meses
Puntos: 2
Respuesta: Detectar dispositivo móvil

Cita:
Iniciado por skiper0125 Ver Mensaje

¿Para que deseas saber el tipo de dispositivo con PHP?

Saluos

Para redireccionar de paginas normales a paginas preparadas para móviles


(Gracias a todos los que han respondido...)
  #8 (permalink)  
Antiguo 28/05/2012, 05:21
Avatar de J_de_Prado  
Fecha de Ingreso: junio-2011
Ubicación: Alpedrete, Madrid,España
Mensajes: 28
Antigüedad: 12 años, 10 meses
Puntos: 2
Respuesta: Detectar dispositivo móvil

Cita:
Iniciado por newboy_master Ver Mensaje
Prueba aquí:

[url]http://detectmobilebrowsers.com/[/url]

La versión en PHP simplemente tiene un condicional, si se verifica te redirecciona a una página, donde supuestamente tendrás la versión móvil.

Salu2.


Gracias
Este es el único código que por lo menos me detecta los simuladores de Android, por el momento no me detecta el simulador de [URL="http://iphone4simulator.com/"]http://iphone4simulator.com/[/URL]

Es posible que pruebe otras cosas, si sale bien lo diré por aquí...

Etiquetas: dispositivo, html, usuarios
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:01.