worm / getclientiplib
GetClientIp 是一个轻量级的 PHP 类,用于获取真实/原始客户端 IP 地址,无需代理如 Opera Mini 等。
1.0.8
2019-04-01 07:52 UTC
Requires
- php: >=5.2.0
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- johnkary/phpunit-speedtrap: ~1.0@dev
- phpunit/phpunit: *
README
GetClientIp 是一个轻量级的 PHP 类,用于获取真实/原始客户端 IP 地址,无需代理如 Opera Mini 等。它使用特定的 $_SERVER 头部来检测客户端 IP 地址。类搜索有效的客户端 IPv4 地址。
Composer 安装
composer require worm/getclientiplib
{ "require": { "worm/getclientiplib": "^1.0" } }
用法
$getClientIp = new GetClientIp; $ip = $getClientIp->getClientIp(); $longIp = $getClientIp->getLongClientIp();
使用手动数据
$getClientIp = new GetClientIp(array( "REMOTE_ADDR" => "1.2.3.4", "REMOTE_PORT" => "", "SERVER_ADDR" => "1.1.1.1", "X_FORWARDED_FOR" => "2.3.4.5,1.2.3.4, 1.2.3.4" )); $ip = $getClientIp->getClientIp(); $longIp = $getClientIp->getLongClientIp();