Jump to content

[SOLVED] Detecting properly formatted IP address


Brandon Jaeger

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.