global.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. /* if running with register_globals = 0 and
  32. magic_quotes_gpc then strip the slashes
  33. from POST and GET global arrays */
  34. if (get_magic_quotes_gpc()) {
  35. if (ini_get('register_globals') == 0) {
  36. sqstripslashes($_GET);
  37. sqstripslashes($_POST);
  38. }
  39. }
  40. /* strip any tags added to the url from PHP_SELF.
  41. This fixes hand crafted url XXS expoits for any
  42. page that uses PHP_SELF as the FORM action */
  43. strip_tags($_SERVER['PHP_SELF']);
  44. function sqstripslashes(&$array) {
  45. foreach ($array as $index=>$value) {
  46. if (is_array($array["$index"])) {
  47. sqstripslashes($array["$index"]);
  48. }
  49. else {
  50. $array["$index"] = stripslashes($value);
  51. }
  52. }
  53. }
  54. function sqsession_register ($var, $name) {
  55. $rg = ini_get('register_globals');
  56. if ( (float)substr(PHP_VERSION,0,3) < 4.1 && empty($rg)) {
  57. global $HTTP_SESSION_VARS;
  58. $HTTP_SESSION_VARS["$name"] = $var;
  59. }
  60. else {
  61. session_register("$name");
  62. }
  63. }
  64. function sqsession_unregister ($name) {
  65. $rg = ini_get('register_globals');
  66. if ( (float)substr(PHP_VERSION,0,3) < 4.1 && empty($rg)) {
  67. global $HTTP_SESSION_VARS;
  68. unset($HTTP_SESSION_VARS["$name"]);
  69. }
  70. else {
  71. session_unregister("$name");
  72. }
  73. }
  74. /**
  75. * Search for the var $name in $_SESSION, $_POST, $_GET
  76. * (in that order) and register it as a global var.
  77. */
  78. function sqextractGlobalVar ($name) {
  79. if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) {
  80. global $_SESSION, $_GET, $_POST;
  81. }
  82. global $$name;
  83. if( isset($_SESSION[$name]) ) {
  84. $$name = $_SESSION[$name];
  85. }
  86. if( isset($_POST[$name]) ) {
  87. $$name = $_POST[$name];
  88. }
  89. else if ( isset($_GET[$name]) ) {
  90. $$name = $_GET[$name];
  91. }
  92. }
  93. ?>