Jump to content

Do you clean $_SERVER ['SERVER_ADDR']; to prevent injections?


cunoodle2

Recommended Posts

If so do you protect against it somehow?

 

That would depend. Any variable being used within a database query should be properly escaped.

 

Is there a way to scan it to make sure that it is only numbers and periods?

 

Yeah, you could use a regular expression.

I appreciate the input.  I guess you can never be too careful with anything these days.  I put together a VERY BASIC function just in case anyone else ever wants to use it in the future.

 

<?php
//check an IP address.  If its properly formatted it returns true if not it returns false
function IsIP($text)
{
if (preg_match('/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/', $text))
{
	return TRUE;
} 
else 
{
	return FALSE;
}
}?>

 

If anyone has any input on possibly how to make my function faster and/or more secure I'm always open for input.

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.