Sanitize POST / Get for Database


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



Copy this code and paste it in your HTML
  1. <?
  2.  
  3. // Must be called AFTER the database connection is opened!
  4. $_POST=sanitize($_POST);
  5. $_GET=sanitize($_GET);
  6. $_COOKIE=sanitize($_COOKIE);
  7. $_REQUEST=sanitize($_REQUEST);
  8.  
  9.  
  10. function sanitize($input){
  11. if(is_array($input)){
  12. foreach($input as $k=>$i){
  13. $output[$k]=sanitize($i);
  14. }
  15. }
  16. else{
  17. $input=stripslashes($input);
  18. }
  19. $output=mysql_real_escape_string($input);
  20. }
  21.  
  22. return $output;
  23. }
  24. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.