CI_Input::valid_ip()

valid_ip($ip[, $which = ''])

Parameters:
  • $ip (string) – IP address
  • $which (string) – IP protocol (‘ipv4’ or ‘ipv6’)
Returns:

TRUE if the address is valid, FALSE if not

Return type:

bool

Takes an IP address as input and returns TRUE or FALSE (boolean) depending on whether it is valid or not.

Note

The $this->input->ip_address() method above automatically validates the IP address.

if ( ! $this->input->valid_ip($ip))
{
        echo 'Not Valid';
}
else
{
        echo 'Valid';
}

Accepts an optional second string parameter of ‘ipv4’ or ‘ipv6’ to specify an IP format. The default checks for both formats.

doc_CodeIgniter
2016-10-15 16:31:40
Comments
Leave a Comment

Please login to continue.