Files
2026-07-27 12:58:44 +03:00

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.

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. Ip is needed for validation, geo and conversions.