global.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * globals.php
  4. *
  5. * Copyright (c) 1999-2002 The SquirrelMail Project Team
  6. * Licensed under the GNU GPL. For full terms see the file COPYING.
  7. *
  8. * This includes code to update < 4.1.0 globals to the newer format
  9. * It also has two session register functions that work across various
  10. * php versions.
  11. *
  12. * $Id$
  13. */
  14. /* convert old-style superglobals to current method
  15. * this is executed if you are running PHP 4.0.x.
  16. * it is run via a require_once directive in validate.php
  17. * and redirect.php. Patch submitted by Ray Black.
  18. */
  19. if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) {
  20. global $_COOKIE, $_ENV, $_FILES, $_GET, $_POST, $_SERVER, $_SESSION;
  21. global $HTTP_COOKIE_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES, $HTTP_GET_VARS,
  22. $HTTP_POST_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS;
  23. $_COOKIE =& $HTTP_COOKIE_VARS;
  24. $_ENV =& $HTTP_ENV_VARS;
  25. $_FILES =& $HTTP_POST_FILES;
  26. $_GET =& $HTTP_GET_VARS;
  27. $_POST =& $HTTP_POST_VARS;
  28. $_SERVER =& $HTTP_SERVER_VARS;
  29. $_SESSION =& $HTTP_SESSION_VARS;
  30. }
  31. function sqsession_register ($var, $name) {
  32. $rg = ini_get('register_globals');
  33. if ( (float)substr(PHP_VERSION,0,3) < 4.1 && empty($rg)) {
  34. global $HTTP_SESSION_VARS;
  35. $HTTP_SESSION_VARS["$name"] = $var;
  36. }
  37. else {
  38. session_register("$name");
  39. }
  40. }
  41. function sqsession_unregister ($name) {
  42. $rg = ini_get('register_globals');
  43. if ( (float)substr(PHP_VERSION,0,3) < 4.1 && empty($rg)) {
  44. global $HTTP_SESSION_VARS;
  45. unset($HTTP_SESSION_VARS["$name"]);
  46. }
  47. else {
  48. session_unregister("$name");
  49. }
  50. }
  51. /**
  52. * Search for the var $name in $_SESSION, $_POST, $_GET
  53. * (in that order) and register it as a global var.
  54. */
  55. function sqextractGlobalVar ($name) {
  56. global $_SESSION, $_GET, $_POST, $$name;
  57. if( isset($_SESSION[$name]) ) {
  58. $$name = $_SESSION[$name];
  59. }
  60. if( isset($_POST[$name]) ) {
  61. $$name = $_POST[$name];
  62. }
  63. else if ( isset($_GET[$name]) ) {
  64. $$name = $_GET[$name];
  65. }
  66. }
  67. ?>