PHP: Validate IP-Address
Question by Guest | 2015-05-29 at 21:03
Is there any PHP function with which you can check an IP address?
I am searching for a function which can tell me whether an arbitrary string is a valid IP address or not.
Related Topics
How to avoid Spam Mails
Tip | 0 Comments
MySQL: Line Breaks in MySQL
Tip | 0 Comments
E-Mail: Reply Address different from Sender Address
Question | 1 Answer
PHP: Validate E-Mail Address
Question | 2 Answers
HTML Form: Redirection depending on Radiobutton or Checkbox State
Tutorial | 0 Comments
Send Form Input as an Array to PHP Script
Tip | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
Since PHP version 5.2.0, you can use the function filter_var().
Here is a small example showing how to verify an IP address using filter_var().
$s = '192.168.0.0'; if (filter_var($s, FILTER_VALIDATE_IP)) { echo "$s is a valid ip address!"; } else { echo "$s is not a valid ip address!"; }In this example, we are using filter_var() with the filter FILTER_VALIDATE_IP and we are checking the content of the variable $s.
2015-05-30 at 16:29