kuza / user-data-capture
捕获项目服务器上的用户数据
1.0.7
2020-01-23 10:21 UTC
Requires
- php: >=5.4.0
- ext-json: *
- geoip2/geoip2: ~2.0
Requires (Dev)
- phpunit/phpunit: 6.*
README
PHP 用户数据捕获库。
此库允许您捕获以下用户详细信息:
- 用户的位置详情,包括大陆、国家、城市、纬度、经度、时区等
- 用户发送到服务器的请求详情。包括它们的请求URI、查询参数和请求体。
- 用户使用的设备。这包括所使用的操作系统的详细信息、浏览器以及他们是否在使用移动设备。
要求
- PHP >= 5.3.7
- cURL 扩展
- Maxmind GeoIP2-City 数据库
为 Linux/Mac OS 用户安装 maxmind geoip 数据库
mkdir /usr/local/share/GeoIP/
wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
tar xvzf GeoLite2-City.tar.gz
mv GeoLite2-City_20190528/GeoLite2-City.mmdb /usr/local/share/GeoIP/GeoLite2-City.mmdb
wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz
tar xvzf GeoLite2-Country.tar.gz
mv GeoLite2-Country_20190528/GeoLite2-Country.mmdb /usr/local/share/GeoIP/GeoLite2-Country.mmdb
wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz
tar xvzf GeoLite2-ASN.tar.gz
mv GeoLite2-ASN_20190528/GeoLite2-ASN.mmdb /usr/local/share/GeoIP/GeoLite2-ASN.mmdb
安装
composer require kuza/user-data-capture
用法
<?php require_once 'vendor/autoload.php'; use Kuza\UserDataCapture\Location; use Kuza\UserDataCapture\UserAgent; use Kuza\UserDataCapture\Request; # Get the user's location details try { $location = new Location("path_to_maxmind_db"); $continent_name = $location->continent_name; $country_name = $location->country_name; $city_name = $location->city_name; $latitude = $location->latitude; $longitude = $location->longitude; $timezone = $location->timezone; } catch (\MaxMind\Db\Reader\InvalidDatabaseException $ex) { echo $ex->getMessage(); } catch (\Exception $ex) { echo $ex->getMessage(); } # Get the user's device details $device = new UserAgent(); $os = $device->platform; $browser = $device->browser; $browser_version = $device->version; $is_mobile = $device->is_mobile; $is_app = $device->is_app; $is_bot = $device->is_bot; # Get request details $request = new Request(); $request_method = $request->method; $query_params = $request->query_params; $body = $request->body; $headers = $request->headers; $full_uri = $request->full_uri; $uri_path = $request->uri_path; ?>
致谢
- 来自 Kuza Lab Ltd 的 Phelix Juma