Posted By

section31 on 10/10/08


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

jdstraughan
Scooter


Input Class - Strip Slashes for Magic Quotes


 / Published in: PHP
 

  1. class Input
  2. {
  3. static public function check_magic_quotes()
  4. {
  5. {
  6. $_GET = Input::fix_slashes($_GET);
  7. $_POST = Input::fix_slashes($_POST);
  8. $_SERVER = Input::fix_slashes($_SERVER);
  9. }
  10. }
  11.  
  12. static public function fix_slashes($arr)
  13. {
  14. if (is_array($arr))
  15. {
  16. foreach ($arr as $k => $v)
  17. {
  18. $arr[$k] = is_array($v) ? Input::fix_slashes($v) : stripslashes($v);
  19. }
  20. return $arr;
  21. }
  22. else
  23. {
  24. return stripslashes($arr);
  25. }
  26. }
  27.  
  28. static public function get($key = '', $default = null)
  29. {
  30. return isset($_GET[$key]) ? $_GET[$key] : $default;
  31. }
  32.  
  33. static public function post($key = '', $default = null)
  34. {
  35. return isset($_POST[$key]) ? $_POST[$key] : $default;
  36. }
  37.  
  38. static public function cookie($key = '', $default = null)
  39. {
  40. return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default;
  41. }
  42.  
  43. static public function server($key = '', $default = null)
  44. {
  45. return isset($_SERVER[$key]) ? $_SERVER[$key] : $default;
  46. }
  47.  
  48. static public function session($key = '', $default = null)
  49. {
  50. return isset($_SESSION[$key]) ? $_SESSION[$key] : $default;
  51. }
  52. }

Report this snippet  

You need to login to post a comment.