nathandentzau / cloudflare-geolocation
一个辅助从 Cloudflare 头部获取大陆和国家信息的库。
1.0.0
2019-09-08 23:51 UTC
Requires
- php: >= 7.2
- symfony/http-foundation: ^3.4 || ^4.0
Requires (Dev)
- phpunit/phpunit: ^8.3
This package is auto-updated.
Last update: 2024-09-09 11:55:20 UTC
README
一个辅助从 Cloudflare 请求头部获取大陆和国家信息的库。
安装方法
您可以使用 Composer 安装此库
$ composer require nathandentzau/cloudflare-geolocation
依赖项
- PHP 7.2+
- Symfony HTTP Foundation 组件。
使用方法
获取当前用户的洲
<?php use NathanDentzau\CloudflareGeolocation\CloudflareGeolocation; use Symfony\Component\HttpFoundation\Request; $request = Request::create(); $geolocation = new CloudflareGeolocation($request); /** @var \NathanDentzau\CloudflareGeolocation\Continent */ $continent = $geolocation->getCurrentContinent();
获取当前用户的国籍
<?php use NathanDentzau\CloudflareGeolocation\CloudflareGeolocation; use Symfony\Component\HttpFoundation\Request; $request = Request::create(); $geolocation = new CloudflareGeolocation($request); /** @var \NathanDentzau\CloudflareGeolocation\Country */ $country = $geolocation->getCurrentCountry();
获取当前用户的连接 IP 地址
<?php use NathanDentzau\CloudflareGeolocation\CloudflareGeolocation; use Symfony\Component\HttpFoundation\Request; $request = Request::create(); $geolocation = new CloudflareGeolocation($request); $ipAddress = $geolocation->getConnectingIp();
许可证
本项目采用 MIT 许可证。