Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.