Validate an IP address in PHP Codeigniter

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


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

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

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.