Jump to content

Does this look right for a decent user input sanitizer


woocha

Recommended Posts

<?php  
function sanitize($value)  
{    
   if(get_magic_quotes_gpc())     
   {      $value = stripslashes($value);    
    }    else     {      
           $value = $value;    }  

  mysql_real_escape_string($value);   
  return $value;  
}?>

Its something I slapped together....do you guys think it makes good sense as a function?

I got this from w3schools.com

 

function check_input($value)
{
    // Stripslashes
    if (get_magic_quotes_gpc()){
	$value = stripslashes($value);
    }
    // Quote if not a number
    if (!is_numeric($value)){
	$value = mysql_real_escape_string($value);
    }
    return $value;
}

Numeric or not, your data should be escaped. Theres a fair bit of redundant code in there, but otherwise, it along with validation should be sufficient.

 

<?php  
function sanitize($value) {    
 if (get_magic_quotes_gpc()) {
   $value = stripslashes($value);    
 }
 return mysql_real_escape_string($value);     
}
?>

Theres a fair bit of redundant code in there

 

OH DUH !!

 

Thanks  :) ...but other than that, you think this should be good for allowing users to login into and register to my site.....STRICTLY SPEAKING ABOUT SQL INJECTION, no other validations

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.