Brandon Jaeger Posted September 12, 2008 Share Posted September 12, 2008 Hi, I'm trying to detect a properly formatted IP address from $_POST data. The IP also has a port in it. How would I detect a properly formatted IP address like this? 72.5.86.196:27015 The ports will vary, so it's not going to be 27015 every time. Currently I'm doing it like so: if(!strlen($s_ip) || strpos($s_ip, ":") !== true || strpos($s_ip, ".") !== true) { $error = true; $error_msg .= "<li>The IP is not formatted correctly or you haven't entered one</li>"; } That method is very simple as you can tell. It doesn't work too well. It always executes whats inside of the curly brackets even when the IP is properly formatted. Thanks. Brandon Quote Link to comment https://forums.phpfreaks.com/topic/123897-solved-detecting-properly-formatted-ip-address/ Share on other sites More sharing options...
Brandon Jaeger Posted September 12, 2008 Author Share Posted September 12, 2008 Nevermind. I figured out a solution. Quote Link to comment https://forums.phpfreaks.com/topic/123897-solved-detecting-properly-formatted-ip-address/#findComment-639614 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.