PHPEdit.net Community
   
1 2 3 4
Tutorials Tips Pasties Code Snippets
 

Home > Code snippets > PHP > Removing Register Globals and Magic Quotes

Removing Register Globals and Magic Quotes

Created by ltp, last update on 26/02/2008 17:29

If you are in the situation where you can not control is register globals are on or if magic quotes are on you need an easy way to remove them. Luckily with a single include file you can remove these items. Whether you are transitioning away from them or are on a host where you can not turn them off this will help you to ensure that the variables are cleaned out.

  1. if (ini_get('register_globals')) {
  2. $rg = array_keys($_REQUEST);
  3. foreach($rg as $v)
  4. {
  5. if ($_REQUEST[$v] === $$v)
  6. {
  7. unset($$v);
  8. }
  9. }
  10. unset($rg);
  11. }
  12.  
  13. $in = array(&$_GET, &$_POST, &$_COOKIE);
  14. while (list($k,$v) = each($in))
  15. {
  16. foreach ($v as $key => $val)
  17. {
  18. if (!is_array($val))
  19. {
  20. $in[$k][$key] = stripslashes($val);
  21. continue;
  22. }
  23. $in[] =& $in[$k][$key];
  24. }
  25. }
  26. unset($in);
  27. }

Dependencies

No special requirements are needed by this snippet

By logging in you will be able to:

  • Recommand this page to someone else
  • Monitor changes on this item
  • Rate this item
  • Post comments
  • Download this item
Login now!

 
PHPEdit User Community, © 2008 WaterProof SARL
Powered by PHPEdit