I want to check if an entered input is a valid IP address or not. I would like a specific function that will help me validate a users input.
// Usually you'd get the value from $_POST or $_GET
$ip = "10.3.1.5";
if(!filter_var($ip, FILTER_VALIDATE_IP)) {
echo "Not a valid IP address!";
}
You can modify this by filtering for IPv4 and IPv6 IP addresses and exclude private and reserved IPs.
http://www.php.net/manual/filter.filters.validate.php