Posted By

Queue on 01/23/13


Tagged

register globals settings


Versions (?)

Unregister Globals Function


 / Published in: PHP
 

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

  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  

You need to login to post a comment.