• Stars
    star
    4,417
  • Rank 9,227 (Top 0.2 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 10 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

👮 A PHP desktop/mobile user agent parser with support for Laravel, based on Mobiledetect

Agent

Latest Stable Version Total Downloads Build Status Coverage Status Donate

A PHP desktop/mobile user agent parser with support for Laravel, based on Mobile Detect with desktop support and additional functionality.

Installation

Install using composer:

composer require jenssegers/agent

Laravel (optional)

Add the service provider in config/app.php:

Jenssegers\Agent\AgentServiceProvider::class,

And add the Agent alias to config/app.php:

'Agent' => Jenssegers\Agent\Facades\Agent::class,

Basic Usage

Start by creating an Agent instance (or use the Agent Facade if you are using Laravel):

use Jenssegers\Agent\Agent;

$agent = new Agent();

If you want to parse user agents other than the current request in CLI scripts for example, you can use the setUserAgent and setHttpHeaders methods:

$agent->setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2');
$agent->setHttpHeaders($headers);

All of the original Mobile Detect methods are still available, check out some original examples at https://github.com/serbanghita/Mobile-Detect/wiki/Code-examples

Is?

Check for a certain property in the user agent.

$agent->is('Windows');
$agent->is('Firefox');
$agent->is('iPhone');
$agent->is('OS X');

Magic is-method

Magic method that does the same as the previous is() method:

$agent->isAndroidOS();
$agent->isNexus();
$agent->isSafari();

Mobile detection

Check for mobile device:

$agent->isMobile();
$agent->isTablet();

Match user agent

Search the user agent with a regular expression:

$agent->match('regexp');

Additional Functionality

Accept languages

Get the browser's accept languages. Example:

$languages = $agent->languages();
// ['nl-nl', 'nl', 'en-us', 'en']

Device name

Get the device name, if mobile. (iPhone, Nexus, AsusTablet, ...)

$device = $agent->device();

Operating system name

Get the operating system. (Ubuntu, Windows, OS X, ...)

$platform = $agent->platform();

Browser name

Get the browser name. (Chrome, IE, Safari, Firefox, ...)

$browser = $agent->browser();

Desktop detection

Check if the user is using a desktop device.

$agent->isDesktop();

This checks if a user is not a mobile device, tablet or robot.

Phone detection

Check if the user is using a phone device.

$agent->isPhone();

Robot detection

Check if the user is a robot. This uses jaybizzle/crawler-detect to do the actual robot detection.

$agent->isRobot();

Robot name

Get the robot name.

$robot = $agent->robot();

Browser/platform version

MobileDetect recently added a version method that can get the version number for components. To get the browser or platform version you can use:

$browser = $agent->browser();
$version = $agent->version($browser);

$platform = $agent->platform();
$version = $agent->version($platform);

Note, the version method is still in beta, so it might not return the correct result.

License

Laravel User Agent is licensed under The MIT License (MIT).

Security contact information

To report a security vulnerability, follow these steps.

More Repositories

1

imagehash

🌄 Perceptual image hashing for PHP
PHP
1,940
star
2

date

🗓 A library to help you work with dates in multiple languages, based on Carbon.
PHP
1,813
star
3

optimus

🤖 Id obfuscation based on Knuth's multiplicative hashing method for PHP.
PHP
1,254
star
4

php-proxy

A PHP proxy script with https and post support
PHP
922
star
5

blade

🔪 A standalone version of Laravel's Blade templating engine for use outside of Laravel.
PHP
752
star
6

model

This model provides an eloquent-like base class that can be used to build custom models in Laravel and other frameworks
PHP
348
star
7

RTL8188-hostapd

hostapd for Realtek RTL8188
C
334
star
8

laravel-rollbar

Rollbar error monitoring integration for Laravel projects
PHP
333
star
9

laravel-ab

A server-side A/B testing tool for Laravel.
PHP
285
star
10

captain

⚓️ Easily start and stop docker compose projects
Go
231
star
11

codeigniter-hmvc-modules

Create HMVC modules with this lightweight extension for Codeiginter 2
PHP
187
star
12

codeigniter-advanced-images

Resize and crop images on the fly
PHP
181
star
13

dashboard

A server dashboard for Ubuntu
PHP
136
star
14

codeigniter-template-library

A template library for Codeigniter
PHP
107
star
15

laravel-raven

Sentry (Raven) error monitoring integration for Laravel projects
PHP
91
star
16

laravel-mongodb-session

A MongoDB session driver for Laravel
PHP
75
star
17

codeigniter-authentication-library

A secure authentication library for CodeIgniter
PHP
67
star
18

laravel-oauth

A Laravel OAuth 1 & 2 library
PHP
65
star
19

laravel-mongodb-sentry

An extension for Laravel-MongoDB that lets you work with Sentry
PHP
53
star
20

codeigniter-message-library

Store and display error or information messages to display on the current page or next page
PHP
51
star
21

lean

Use the PHP League's Container package with auto-wiring support as the core container in Slim 3
PHP
31
star
22

laravel-mongodb-core

A MongoDB based query builder for Laravel
PHP
25
star
23

php-chef

Opscode Chef API PHP library
PHP
20
star
24

chef-patch

Helps you replace text and lines in files from Chef recipes.
Ruby
20
star
25

palenight.zsh-theme

My custom zsh theme
13
star
26

laravel-mongodb-lite

A lightweight MongoDB database library and model for Laravel 4
PHP
11
star
27

vagrant

My personal Vagrant development environment
HTML
7
star
28

docker

My personal Docker setup
5
star
29

docker-php-cs-fixer

A tool to automatically fix PHP coding standards issues
4
star
30

quotebot

Quotebot for slack
TypeScript
4
star
31

ddd-oke-cars

PHP
4
star
32

docker-php

Custom PHP docker image with some basic extensions
Dockerfile
4
star
33

cryptonope

Replace crypto words with random things
JavaScript
3
star
34

homebrew-custom

Custom homebrew formulas
Ruby
2
star
35

spacegray-monokai

A Monokai color scheme for Sublime's Spacegray theme
1
star