Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Aug 052011
 

Validate IP address in PHP

Answer:

If you are using PHP 5.2 or above (in fact, at the moment of writing, you should use at least PHP 5.3+), you can use the following easy method:

if(filter_var($ip, FILTER_VALIDATE_IP)) 
{
  // Valid IP
}
else 
{
  // Invalid IP
}

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>