Function __global->get_ip_address

Definitions

sources/global3.php

  • Attempt to get the clean IP address of the current user.Note we do not consider potential proxying because that can easily be forged, and even if not it could be some local IP that is not unique enough.The software has support for deproxying in global.php, which will adjust REMOTE_ADDR well in advance of this function being called.
  • Visibility: public
  • Is abstract?: No
  • Is static?: No
  • Is final?: No
  • Returns: string

Parameters

Name Type Passed by reference? Variadic? Default Set Range Description
$amount integer No No 4 1 2 3 4 N/A The number of groups to include in the IP address (rest will be replaced with *'s). For IP6, this is doubled.
$ip ?IP No No Null N/A N/A IP address to use, normally left null (null: current user's)

Returns

  • The users IP address (blank: could not find a valid one)
  • Type: IP
  • Set: N/A
  • Range: N/A

Preview

Code (PHP)

/**
 * Attempt to get the clean IP address of the current user.Note we do not consider potential proxying because that can easily be forged, and even if not it could be some local IP that is not unique enough.The software has support for deproxying in global.php, which will adjust REMOTE_ADDR well in advance of this function being called.
 *
 * @param  integer $amount The number of groups to include in the IP address (rest will be replaced with *'s). For IP6, this is doubled.
 * @set 1 2 3 4
 * @param  ?IP $ip IP address to use, normally left null (null: current user's)
 * @return IP The users IP address (blank: could not find a valid one)
 */

function get_ip_address(int $amount = 4, ?string $ip = null) : string