PHP – Validaciones – Dispotivo móvil
Función que nos permite detectar si en dispotivo actual es un dispositivo móvil. Para ello detectamos la variable HTTP_USER_AGENT del $_SERVER y miramos el texto que identifica a cada marca y/o modelo.
/**
* Class HelperValidate
*/
abstract class HelperValidate
{
/**
* Indica si el dispositivo es un dispositivo móvil
* @return bool
* @see servidor_value
* @see strLower
*/
public static function isDeviceMobile() : bool
{
$httpAgent = HelperServer::getValue('HTTP_USER_AGENT');
$iPod = stripos($httpAgent, "ipod") !== false;
$iPhone = stripos($httpAgent, "iphone") !== false;
$iPad = stripos($httpAgent, "ipad") !== false;
$Android = stripos($httpAgent, "android") !== false;
$webOS = stripos($httpAgent, "webos") !== false;
$blackberry = stripos($httpAgent, "blackberry") !== false;
return ( $iPod ||
$iPhone ||
$iPad ||
$Android ||
$webOS ||
$blackberry);
}
}
Funciones relacionadas
- HelperServer::getValue : Obtener un valor del array $_SERVER con filter_input
- HelperString:toLower : Convertir un texto a minúsculas con acentos
