global.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 some 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 magic_quotes_gpc then strip the slashes
  32. from POST and GET global arrays */
  33. if (get_magic_quotes_gpc()) {
  34. sqstripslashes($_GET);
  35. sqstripslashes($_POST);
  36. }
  37. /* strip any tags added to the url from PHP_SELF.
  38. This fixes hand crafted url XXS expoits for any
  39. page that uses PHP_SELF as the FORM action */
  40. strip_tags($_SERVER['PHP_SELF']);
  41. function sqstripslashes(&$array) {
  42. foreach ($array as $index=>$value) {
  43. if (is_array($array["$index"])) {
  44. sqstripslashes($array["$index"]);
  45. }
  46. else {
  47. $array["$index"] = stripslashes($value);
  48. }
  49. }
  50. }
  51. function sqsession_register ($var, $name) {
  52. if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) {
  53. global $HTTP_SESSION_VARS;
  54. $HTTP_SESSION_VARS["$name"] = $var;
  55. }
  56. else {
  57. $_SESSION["$name"] = $var;
  58. }
  59. }
  60. function sqsession_unregister ($name) {
  61. if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) {
  62. global $HTTP_SESSION_VARS;
  63. unset($HTTP_SESSION_VARS["$name"]);
  64. }
  65. else {
  66. unset($_SESSION["$name"]);
  67. }
  68. }
  69. function sqsession_is_registered ($name) {
  70. $test_name = &$name;
  71. $result = false;
  72. if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) {
  73. global $HTTP_SESSION_VARS;
  74. if (isset($HTTP_SESSION_VARS[$test_name])) {
  75. $result = true;
  76. }
  77. }
  78. else {
  79. if (isset($_SESSION[$test_name])) {
  80. $result = true;
  81. }
  82. }
  83. return $result;
  84. }
  85. /**
  86. * Search for the var $name in $_SESSION, $_POST, $_GET
  87. * (in that order) and register it as a global var.
  88. */
  89. function sqextractGlobalVar ($name) {
  90. if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) {
  91. global $_SESSION, $_GET, $_POST;
  92. }
  93. global $$name;
  94. if( isset($_SESSION[$name]) ) {
  95. $$name = $_SESSION[$name];
  96. }
  97. if( isset($_POST[$name]) ) {
  98. $$name = $_POST[$name];
  99. }
  100. else if ( isset($_GET[$name]) ) {
  101. $$name = $_GET[$name];
  102. }
  103. }
  104. function sqsession_destroy() {
  105. global $base_uri;
  106. /* start session to be able to destroy it later */
  107. session_start();
  108. if ( (float)substr(PHP_VERSION , 0 , 3) < 4.1) {
  109. global $HTTP_SESSION_VARS;
  110. $HTTP_SESSION_VARS = array();
  111. }
  112. else {
  113. $_SESSION = array();
  114. }
  115. /*
  116. * now reset cookies to 5 seconds ago to delete from browser
  117. */
  118. @session_destroy();
  119. $cookie_params = session_get_cookie_params();
  120. setcookie(session_name(), '', time() - 5, $cookie_params['path'],
  121. $cookie_params['domain']);
  122. setcookie('username', '', time() - 5, $base_uri);
  123. setcookie('key', '', time() - 5 , $base_uri);
  124. }
  125. ?>