Re: MySQL Sanitization

From sixx, 1 Year ago, written in PHP, viewed 90 times. This paste is a reply to MySQL Sanitization from sixx - go back
URL https://paste.bugabuse.net/view/f8d5d01f/diff Embed
Viewing differences between MySQL Sanitization and Re: MySQL Sanitization
//Revision 2, fixed an error


//First function is to remove malicious characters

<?php
function cleanInput($input) {
 
  $search = array(
    '@<script[^>]*?>.*?</script>@si',   // Strip out javascript
    '@<[\/\!]*?[^<>]*?>@si',            // Strip out HTML tags
    '@<style[^>]*?>.*?</style>@siU',    // Strip style tags properly
    '@<![\s\S]*?--[ \t\n\r]*>@'         // Strip multi-line comments
  );
 
    $output = preg_replace($search, '', $input);
    return $output;
  }
?>

//Second function implements first function and does the actual sanitation

<?php
function sanitize($input) {
    if (is_array($input)) {
        foreach($input as $var=>$val) {
            $output[$var] = sanitize($val);
        }
    }
    else {
        if (get_magic_quotes_gpc()) {
            $input = stripslashes($input);
        }
        $input  = cleanInput($input);
        $output = mysql_real_escape_string($input);
    }
    return $output;
}
?>

//Example use on phisher

<?php
$username = sanitize($_POST["username"]
sanitize($_POST["username"]);
?>

//Signed
-sixxfeetundr

Reply to "Re: MySQL Sanitization"

Here you can reply to the paste above