Posted By

SteveMcDaniel on 10/09/09


Tagged

php stripslashesmysqlrealescapestringGETPOST


Versions (?)

Who likes this?

9 people have marked this snippet as a favorite

snookout
vali29
silentbob84
aleksanderek
joethermal
chopbust
sbcjr
osccar
ringo380


Sanitize POST / Get for Database


 / Published in: PHP
 

  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  

You need to login to post a comment.