Validate an IP address in PHP Codeigniter

To retrieve the user’s IP address we can use the following line of code in codeigniter

$this->input->ip_address();

If the IP address is not valid, it will return 0.0.0.0. We can use the same code to validate an ip address as shown below

$ip = "192.168.1.1";
if (!$this->input->valid_ip($ip))
{
  echo " Not a valid IP address" ;
}
else
{
  echo " Valid IP address! " ;
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.