Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 24, 2019 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/9e63af8df7663784ef91b43cb6fbaa92 to your computer and use it in GitHub Desktop.
Save parzibyte/9e63af8df7663784ef91b43cb6fbaa92 to your computer and use it in GitHub Desktop.
<?php
/**
* Demostrar uso de librería uap-php
*
* https://parzibyte.me/blog
*/
require_once "vendor/autoload.php";
use UAParser\Parser;
# Podría venir de otro lado
$agenteDeUsuario = $_SERVER["HTTP_USER_AGENT"];
$parseador = Parser::create();
$resultado = $parseador->parse($agenteDeUsuario);
$familiaNavegador = $resultado->ua->family; // Chrome, Firefox, Safari, Edge
$navegador = $resultado->ua->toString();
$dispositivo = $resultado->device->family;
$familiaSistema = $resultado->os->family;
$sistema = $resultado->os->toString();
$completo = $resultado->toString();
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Información de navegador</title>
</head>
<body>
<strong>Familia de navegador: </strong> <?php echo $familiaNavegador ?><br>
<strong>Navegador: </strong> <?php echo $navegador ?><br>
<strong>Dispositivo: </strong> <?php echo $dispositivo ?><br>
<strong>Familia de OS: </strong> <?php echo $familiaSistema ?><br>
<strong>Sistema operativo: </strong> <?php echo $sistema ?><br>
<strong>Información completa: </strong> <?php echo $completo ?><br>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment