Using PHP to Validate an IP Address

You can use the PHP code below to check if an IP address is valid or not.

$ip = ""; //enter a valid or invalid ip address here
if(filter_var($ip, FILTER_VALIDATE_IP)) {
  // The IP Address is valid
} else {
  // The IP Address is not valid
}

Wasn’t that easy!?!