Search code snippets, questions, articles...

Validate IP address using filter_var() method PHP

You can use filter_var() with FILTER_VALIDATE_IP to validate an IP address in PHP. Below is the code example for that.
    $ip_address = "";

    if (filter_var($ip_address, FILTER_VALIDATE_IP) == true) {
        echo("Valid IP");
    } else {
        echo("Invalid Ip");
Was this helpful?
Programming Feeds
Learn something new everyday on Devsheet