guiliredu/simple-user-agent

A package to get info from a user agent

1.0.2 2020-10-27 21:19 UTC

This package is auto-updated.

Last update: 2024-11-28 06:08:02 UTC


README

A simple class to parse data from a user agent.

<?php

require __DIR__ . '/vendor/autoload.php';

use SimpleUserAgent\UserAgent;

$agent = new UserAgent();

You can set a user agent in the first parameter of the constructor. If the parameter is empty, it will try to parse data from $_SERVER['HTTP_USER_AGENT']

$agent = new UserAgent('Mozilla/5.0 ...');

You can set a user agent after instantiation, calling this method:

$agent->setAgent('Mozilla/5.0 ...');

To get the data, you can call these available methods

$agent->getAgent() // Full user agent string
$agent->getDevice() // iPhone
$agent->getOS() // iOS
$agent->getBrowser() // Apple Safari
$agent->getPrefix() // Safari
$agent->getVersion() // 11.0
$agent->getEngine() // WebKit
$agent->isBot() // true / false
$agent->getInfo() // Array with all the above info

This project is under development - For test purposes only

References: