gitmyhub

agent

PHP ★ 4.8k updated 1y ago

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

A PHP library that detects what device, browser, and operating system a website visitor is using, so your app can respond differently to phones, tablets, desktops, and bots.

PHPLaravelComposerMobile DetectCrawler Detectsetup: easycomplexity 2/5

Agent is a PHP library that reads the user agent string sent by a visitor's browser and tells you what device, operating system, and browser they are using. When someone visits a website, their browser sends a short text string identifying itself. This string is called a user agent, and while it contains useful information, parsing it correctly requires handling a large variety of formats and edge cases. Agent wraps an existing library called Mobile Detect and extends it with additional detection capabilities for desktop browsers and more detailed device information.

With Agent, a PHP application can ask questions like: is this visitor on a mobile phone, a tablet, or a desktop computer? Which browser are they using? What operating system? Is the request coming from a search engine crawler rather than a real person? Each of these checks returns a simple true or false, or a string with the name of the detected device or software. For example, you can call methods to get the browser name, the platform name, the device name, and the version numbers of each.

The library integrates with the Laravel PHP framework through a service provider and a facade, which are the standard Laravel mechanisms for adding third-party packages. In a non-Laravel project it can also be used as a plain PHP class. Installation is handled through Composer, the standard PHP package manager.

Agent is built on top of the Mobile Detect library, so all of Mobile Detect's detection methods are available in addition to the new ones Agent adds. Robot detection is handled by a separate library called Crawler Detect, which is included as a dependency. The library is licensed under the MIT license.

Where it fits