Clean variables from SQL injections


/ Published in: PHP
Save to your folder(s)

This little function helps to fight common security issue with SQL injections, it can sanitize any global variable like $_POST, $_GET, $_SERVER etc and escape unsafe characters.


Copy this code and paste it in your HTML
  1. function _clean($str){
  2. return is_array($str) ? array_map('_clean', $str) : str_replace("\\", "\\\\", htmlspecialchars((get_magic_quotes_gpc() ? stripslashes($str) : $str), ENT_QUOTES));
  3. }
  4.  
  5. //usage call it somewhere in beginning of your script
  6. _clean($_POST);
  7. _clean($_GET);
  8. _clean($_REQUEST);// and so on..

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.