explaingit

jenssegers/agent

4,780PHPAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

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.

Mindmap

mindmap
  root((agent))
    What it does
      Detects device type
      Detects browser
      Detects OS
      Detects bots
    Tech Stack
      PHP
      Laravel
      Composer
    Use Cases
      Mobile redirects
      Bot blocking
      Browser logging
    Audience
      PHP developers
      Laravel users
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Show a mobile-optimized layout when a visitor arrives on a phone or tablet.

USE CASE 2

Block or log requests from search engine crawlers instead of serving them normal pages.

USE CASE 3

Redirect users to a separate mobile subdomain based on their device type.

USE CASE 4

Log which browsers and operating systems your users are on to guide browser support decisions.

Tech stack

PHPLaravelComposerMobile DetectCrawler Detect

Getting it running

Difficulty · easy Time to first run · 5min
Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

In plain English

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.

Copy-paste prompts

Prompt 1
Using the jenssegers/agent PHP library in a Laravel app, write a middleware that redirects mobile users to /mobile and lets desktop users through normally.
Prompt 2
Show me how to detect if a visitor is a search engine crawler with jenssegers/agent and return an early 403 response.
Prompt 3
Using jenssegers/agent outside of Laravel, detect the browser name, OS name, and device name from a user agent string and print each one.
Prompt 4
Write a Laravel Blade component that shows a different header for mobile vs desktop using jenssegers/agent.
Open on GitHub → Explain another repo

← jenssegers on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.