We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

peteypablonz on 11/21/07


Tagged

get mysql sql php post input cookie injection clean


Versions (?)


Who likes this?

19 people have marked this snippet as a favorite

basicmagic
peteypablonz
vali29
brent-man
benrasmusen
naz
skywalker
JimiJay
cristianciofu
dyesin
mb
ibomb
Nix
romanos
pixelhandler
chph
davidhorn
sumandahal
joaosalless


clean user input data ( GET, POST, COOKIE )


Published in: PHP 


URL: http://www.meelsonwheels.com

Created for my own purposes, thought I'd share though ;)

copy paste at the top of your file and it does the magic :)

  1. <?php
  2.  
  3. function clean($value)
  4. {
  5. if (get_magic_quotes_gpc()) $value = stripslashes($value);
  6.  
  7. if (!is_numeric($value)) $value = mysql_real_escape_string($value);
  8.  
  9. return $value;
  10. }
  11.  
  12. array_walk($_GET,'clean');
  13. array_walk($_POST,'clean');
  14. array_walk($_COOKIE,'clean');
  15.  
  16. extract($_GET,EXTR_PREFIX_ALL,'get');
  17. extract($_POST,EXTR_PREFIX_ALL,'post');
  18. extract($_COOKIE,EXTR_PREFIX_ALL,'cookie');
  19.  
  20. ?>

Report this snippet 

You need to login to post a comment.