MySQL Sanitization

From sixx, 1 Year ago, written in PHP, viewed 93 times.
URL https://paste.bugabuse.net/view/6c0155ad Embed
Download Paste or View Raw
  1. //First function is to remove malicious characters
  2.  
  3. <?php
  4. function cleanInput($input) {
  5.  
  6.   $search = array(
  7.     '@<script[^>]*?>.*?</script>@si',   // Strip out javascript
  8.     '@<[\/\!]*?[^<>]*?>@si',            // Strip out HTML tags
  9.     '@<style[^>]*?>.*?</style>@siU',    // Strip style tags properly
  10.     '@<![\s\S]*?--[ \t\n\r]*>@'         // Strip multi-line comments
  11.   );
  12.  
  13.     $output = preg_replace($search, '', $input);
  14.     return $output;
  15.   }
  16. ?>
  17.  
  18. //Second function implements first function and does the actual sanitation
  19.  
  20. <?php
  21. function sanitize($input) {
  22.     if (is_array($input)) {
  23.         foreach($input as $var=>$val) {
  24.             $output[$var] = sanitize($val);
  25.         }
  26.     }
  27.     else {
  28.         if (get_magic_quotes_gpc()) {
  29.             $input = stripslashes($input);
  30.         }
  31.         $input  = cleanInput($input);
  32.         $output = mysql_real_escape_string($input);
  33.     }
  34.     return $output;
  35. }
  36. ?>
  37.  
  38. //Example use on phisher
  39.  
  40. <?php
  41. $username = sanitize($_POST["username"]
  42. ?>
  43.  
  44. //Signed
  45. -sixxfeetundr

Replies to MySQL Sanitization rss

Title Name Language When
Re: MySQL Sanitization sixx php 1 Year ago.

Reply to "MySQL Sanitization"

Here you can reply to the paste above