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!?!

Tags:
0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments