Unregister Globals Function


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

Emulate Register Globals being Off when you can't (or don't want to) change php.ini for your entire site


Copy this code and paste it in your HTML
  1. function unregister_globals() {
  2.  
  3. if (ini_get('register_globals') == 0) {
  4. return;
  5. }
  6.  
  7. // Save the existing superglobals first
  8. $REQUEST = $_REQUEST;
  9. $GET = $_GET;
  10. $POST = $_POST;
  11. $COOKIE = $_COOKIE;
  12.  
  13. if (isset($_SESSION)) {
  14. $SESSION = $_SESSION;
  15. }
  16.  
  17. $FILES = $_FILES;
  18. $ENV = $_ENV;
  19. $SERVER = $_SERVER;
  20.  
  21. // Unset the $GLOBALS array (clear all)
  22. foreach($GLOBALS as $key => $value) {
  23. if ($key != 'GLOBALS') {
  24. unset($GLOBALS[$key]);
  25. }
  26. }
  27.  
  28. // Re-assign the saved superglobals again
  29. $_REQUEST = $REQUEST;
  30. $_GET = $GET;
  31. $_POST = $POST;
  32. $_COOKIE = $COOKIE;
  33.  
  34. if (isset($SESSION)) {
  35. $_SESSION = $SESSION;
  36. }
  37.  
  38. $_FILES = $FILES;
  39. $_ENV = $ENV;
  40. $_SERVER = $SERVER;
  41. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.