effectra/tracker

Effectra Tracker 包。

v1.0.0 2023-09-29 10:44 UTC

This package is auto-updated.

Last update: 2024-09-29 13:00:32 UTC


README

Effectra Tracker 是一个 PHP 包,提供了从客户端请求中提取信息的方法,包括 IP 地址、浏览器详情、操作系统、设备类型、接受的语言和来源 URL。它还包括与 IP 追踪服务的集成,以获取与提供的 IP 地址相关的附加属性。

安装

您可以通过 Composer 安装 Effectra Tracker 包。

composer require effectra/tracker

用法

追踪器类

初始化追踪器

use Effectra\Tracker\Tracker;
use Psr\Http\Message\ServerRequestInterface;

$request = ...; // Your PSR-7 ServerRequestInterface implementation
$tracker = new Tracker($request);

获取客户端 IP 地址

$ipAddress = $tracker->getIp();

获取浏览器详情

$browser = $tracker->getBrowser();
// $browser['name'] contains the browser name
// $browser['version'] contains the browser version

获取操作系统详情

$os = $tracker->getOs();
// $os['name'] contains the OS name
// $os['version'] contains the OS version

获取设备类型

$deviceType = $tracker->getDevice();

获取用户代理

$userAgent = $tracker->getUserAgent();

获取接受的语言

$acceptedLanguages = $tracker->getAcceptLangs();

获取来源 URL

$refererUrl = $tracker->getReferer();

检查客户端是否使用手机设备

$isPhone = $tracker->isPhone();

获取所有客户端信息

$clientInfo = $tracker->getAll();
// $clientInfo is an associative array containing all client information

IP 追踪服务集成

Effectra Tracker 支持与各种 IP 追踪服务的集成。目前支持以下服务

IpGeoLocation 服务

use Effectra\Tracker\Services\IpGeoLocation;
use GuzzleHttp\Client;

$client = new Client(); // GuzzleHttp client instance
$ip = ...; // IP address to query
$apiKey = ...; // Your API key for ipgeolocation.io

$ipGeoLocation = new IpGeoLocation($client, $ip, $apiKey);
$ipAttributes = $ipGeoLocation->getAll();

IpRegistry 服务

use Effectra\Tracker\Services\IpRegistry;
use GuzzleHttp\Client;

$client = new Client(); // GuzzleHttp client instance
$ip = ...; // IP address to query
$apiKey = ...; // Your API key for ipregistry.co

$ipRegistry = new IpRegistry($client, $ip, $apiKey);
$ipAttributes = $ipRegistry->getAll();

IpWhoIs 服务

use Effectra\Tracker\Services\IpWhoIs;
use GuzzleHttp\Client;

$client = new Client(); // GuzzleHttp client instance
$ip = ...; // IP address to query

$ipWhoIs = new IpWhoIs($client, $ip, null); // No API key required for ipwho.is
$ipAttributes = $ipWhoIs->getAll();

要求

作者

许可协议

本项目采用 MIT 许可协议 - 详细信息请参阅 LICENSE 文件。