mirror of
https://github.com/avecms/AVE.cms.git
synced 2026-08-01 08:45:44 +00:00
1.1 KiB
1.1 KiB
Ip - IP address and geo
App\Helpers\Ip - IP determination and validation, geo-data, conversion. Unlike
most helpers, has both instance mode (new Ip($options)) and static
methods.
use App\Helpers\Ip;
Definition and verification
###getIp()
Client IP taking into account proxy headers (X-Forwarded-For, etc.).
$ip = Ip::getIp();
###isValid($ip = null)
Is the IP valid (current by default).
if (Ip::isValid($ip)) { ... }
Geo data
geoBaseData() - data from the geo-base.
getValue($key = false, $cookie = true) — geo/IP value by key (with cache in cookie).
parseString($string) — parse a string with IP/geo.
Conversion
ip2hex($ip) / hex2ip($hex)
IP ↔ hex representation (compact storage/indexing).
$hex = Ip::ip2hex('192.168.0.1');
$ip = Ip::hex2ip($hex);
Instance mode
$geo = new Ip(['some' => 'options']);
// далее методы экземпляра согласно реализации
For IP specifically current request
Request::ip()is simpler.Ipis needed for validation, geo and conversions.