Skip to content

Latest commit

 

History

History
124 lines (95 loc) · 2.93 KB

README.md

File metadata and controls

124 lines (95 loc) · 2.93 KB

User Agent Parser API - PHP Package

User Agent Parser parses user agent strings to extract browser, operating system, and hardware details. It identifies device types, CPU architecture, and bot traffic, so you can run user agent detection on every incoming HTTP request.

Installation

Install via Composer:

composer require apiverve/useragentparser

Getting Started

Get your API key at APIVerve

Basic Usage

<?php

require_once 'vendor/autoload.php';

use APIVerve\Useragentparser\Client;

// Initialize the client
$client = new Client('YOUR_API_KEY');

// Make a request
$response = $client->execute(['ua' => 'Mozilla/5.0 (Windows NT 6.4) AppleWebKit/537.36.0 (KHTML, like Gecko) Chrome/60.0.0.0 Safari/537.36.0']);

// Print the response
print_r($response);

Error Handling

use APIVerve\Useragentparser\Client;
use APIVerve\Useragentparser\Exceptions\APIException;
use APIVerve\Useragentparser\Exceptions\ValidationException;

try {
    $response = $client->execute(['ua' => 'Mozilla/5.0 (Windows NT 6.4) AppleWebKit/537.36.0 (KHTML, like Gecko) Chrome/60.0.0.0 Safari/537.36.0']);
    print_r($response['data']);
} catch (ValidationException $e) {
    echo "Validation error: " . implode(', ', $e->getErrors());
} catch (APIException $e) {
    echo "API error: " . $e->getMessage();
    echo "Status code: " . $e->getStatusCode();
}

Debug Mode

// Enable debug logging
$client = new Client(
    apiKey: 'YOUR_API_KEY',
    debug: true
);

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "ua": "Mozilla/5.0 (Windows NT 6.4) AppleWebKit/537.36.0 (KHTML, like Gecko) Chrome/60.0.0.0 Safari/537.36.0",
    "browser": {
      "name": "Chrome",
      "version": "60.0.0.0",
      "major": "60"
    },
    "engine": {
      "name": "Blink",
      "version": "60.0.0.0"
    },
    "os": {
      "name": "Windows",
      "version": "10"
    },
    "device": {},
    "cpu": {},
    "isMobile": false,
    "isBot": false,
    "deviceType": "desktop",
    "clientType": "browser",
    "library": null,
    "isSuspicious": false,
    "suspiciousReasons": [],
    "osVersionFrozen": true,
    "versionCheck": {
      "browserFamily": "Chrome",
      "latestVersion": "156",
      "majorsBehind": 95,
      "isOutdated": true,
      "osEndOfLife": null
    },
    "summary": "Chrome 60 on Windows 10"
  }
}

Requirements

  • PHP 7.4 or higher
  • Guzzle HTTP client

Documentation

For more information, visit the API Documentation.

Support

License

This package is available under the MIT License.