validators\IpValidator setRanges()

setRanges() public method

Set the IPv4 or IPv6 ranges that are allowed or forbidden.

The following preparation tasks are performed:

  • Recursively substitutes aliases (described in $networks) with their values.
  • Removes duplicates
public void setRanges ( $ranges )
$ranges array

The IPv4 or IPv6 ranges that are allowed or forbidden.

When the array is empty, or the option not set, all IP addresses are allowed.

Otherwise, the rules are checked sequentially until the first match is found. An IP address is forbidden, when it has not matched any of the rules.

Example:

[
     'ranges' => [
         '192.168.10.128'
         '!192.168.10.0/24',
         'any' // allows any other IP addresses
     ]
]

In this example, access is allowed for all the IPv4 and IPv6 addresses excluding the 192.168.10.0/24 subnet. IPv4 address 192.168.10.128 is also allowed, because it is listed before the restriction.

doc_Yii
2016-10-30 17:13:56
Comments
Leave a Comment

Please login to continue.