Jump to content

Sanitizing Function


bobicles2

Recommended Posts

function clean($input) {
	$input = @trim($input);
	if(get_magic_quotes_gpc()) {
		$input = stripslashes($input);
	}
	return mysql_real_escape_string($input);
}

 

i orginally had this function, shown above to clean up my inputs and prevent SQL injection. However, Magic_quotes_gpc is no longer supported. and this method although clear to me seems a little long winded!

 

is there an easier way for me to clean up my inputs thoroughly? and to avoid SQL injection

 

 

thanks

rob

Link to comment
https://forums.phpfreaks.com/topic/199714-sanitizing-function/
Share on other sites

since magic quotes is no longer supported, I suppose you could just get rid of the if statement. something like

function clean($var){
return mysql_real_escape_string(trim($var));
}

 

should suffice.

 

However, it may be a good idea to keep the if statement so your code is more portable. If you use that code on a server with php 4 or 5 (and magic quotes gpc is enabled) then it may not work as suspected.

 

 

Link to comment
https://forums.phpfreaks.com/topic/199714-sanitizing-function/#findComment-1048221
Share on other sites

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.