$sessiongetIP()

Get the IP address of the current user

Example

$ip = $session->getIP();
echo $ip; // outputs 1.2.3.4

Usage

// basic usage
$string = $session->getIP();

// usage with all arguments
$string = $session->getIP(bool $int = false, $useClient = false, int $numParts = 0);

Arguments

NameType(s)Description
$int (optional)bool

Return as a long integer? Default:false

  • IPv6 addresses cannot be represented as an integer, so please note that using this int option makes it return a CRC32 integer when using IPv6 addresses 3.0.184+.
  • Note that collapsed IPv6 addresses are normalized to fully expanded form in 3.0.258+.
$useClient (optional)bool int

Give preference to client headers for IP? HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR Default:false

  • Specify integer 2 to include potential multiple CSV separated IPs (when provided by client).
$numParts (optional)int

Get partial IP starting from beginning? Specify num of parts for IP to include or omit (0) for full IP.

  • Note that for IPv6 addresses this value is doubled.
  • This argument does not apply if the $int argument is true.
  • This argument is available in ProcessWire 3.0.258 or newer.

Return value

string int

Returns string by default, or integer if $int argument indicates to.


$session methods and properties

API reference based on ProcessWire core version 3.0.257