Free Programming Tutorials & Source Code

 
  • Increase font size
  • Default font size
  • Decrease font size
Home PHP PHP Function to Prevent SQL injection

PHP Function to Prevent SQL injection

E-mail
(1 vote, average: 5.00 out of 5)
Function to clean user input string to prevent SQL injections:



function cleanmaliciousstring($badurl){
    if (get_magic_quotes_gpc()) {
        $cleanurl = mysql_real_escape_string(stripslashes($badurl));    
    }else{
        $cleanurl = mysql_real_escape_string($badurl);    
    }
    return $cleanurl;
}

Enjoy!