You are here

function visitors_is_ip_valid in Visitors 7

Same name and namespace in other branches
  1. 8 visitors.exit.inc \visitors_is_ip_valid()
  2. 7.2 visitors.exit.inc \visitors_is_ip_valid()
  3. 7.0 visitors.exit.inc \visitors_is_ip_valid()

Verify the syntax of the given ip address.

Parameters

ip: A string containing an ip address.

Return value

TRUE if the ip is in a valid format, FALSE on failure.

2 calls to visitors_is_ip_valid()
visitors_get_ip in ./visitors.exit.inc
Get visitors ip address.
visitors_host_hits in reports/hosts.inc
Menu callback; presents the "hits from" page.

File

./visitors.exit.inc, line 18
Implements of hook_exit().

Code

function visitors_is_ip_valid($ip) {
  $result = preg_match('/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/', $ip, $matches);
  return $result && isset($matches[0]) && $matches[0] === $ip && $matches[1] >= 1 && $matches[1] <= 255 && $matches[2] >= 0 && $matches[2] <= 255 && $matches[3] >= 0 && $matches[3] <= 255 && $matches[4] >= 0 && $matches[4] <= 255;
}