From d7c82551df7a28530139681c44a283836be6b6fc Mon Sep 17 00:00:00 2001 From: jmunro Date: Sun, 6 Oct 2002 23:43:02 +0000 Subject: [PATCH] Since changing to rg=0 we make extensive use of $_SESSION and $HTTP_SESSION_VARS. Because of this session_register, session_unregister, and session_is_registered should NOT be used (see the PHP manual at php.net). They are buggy over different PHP versions anyway. Now when changing a session var using the custom 'sq' version of these functions (all located in global.php) the superglobal array is accessed directly. This fixes the problem with corrupted objects in the session. Tested with 4.1.2 rg=0 and 1. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3782 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/auth.php | 8 ++++---- functions/global.php | 29 ++++++++++++++++++++++------- functions/imap_messages.php | 8 ++++---- functions/prefs.php | 2 +- src/compose.php | 2 +- src/redirect.php | 2 +- src/right_main.php | 12 ++++++------ themes/random.php | 2 +- 8 files changed, 40 insertions(+), 25 deletions(-) diff --git a/functions/auth.php b/functions/auth.php index 10c33294..7a6a0fd4 100644 --- a/functions/auth.php +++ b/functions/auth.php @@ -13,7 +13,7 @@ function is_logged_in() { - if ( session_is_registered('user_is_logged_in') ) { + if ( sqsession_is_registered('user_is_logged_in') ) { return; } else { global $HTTP_POST_VARS, $PHP_SELF, $session_expired_post, @@ -24,10 +24,10 @@ function is_logged_in() { */ $session_expired_post = $HTTP_POST_VARS; $session_expired_location = $PHP_SELF; - if (!session_is_registered('session_expired_post')) { + if (!sqsession_is_registered('session_expired_post')) { session_register('session_expired_post'); } - if (!session_is_registered('session_expired_location')) { + if (!sqsession_is_registered('session_expired_location')) { session_register('session_expired_location'); } include_once( '../functions/display_messages.php' ); @@ -36,4 +36,4 @@ function is_logged_in() { } } -?> \ No newline at end of file +?> diff --git a/functions/global.php b/functions/global.php index fcaceff0..b9d63097 100644 --- a/functions/global.php +++ b/functions/global.php @@ -62,26 +62,41 @@ function sqstripslashes(&$array) { } function sqsession_register ($var, $name) { - $rg = ini_get('register_globals'); - if ( (float)substr(PHP_VERSION,0,3) < 4.1 && empty($rg)) { + if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) { global $HTTP_SESSION_VARS; $HTTP_SESSION_VARS["$name"] = $var; } else { - session_register("$name"); + $_SESSION["$name"] = $var; } } function sqsession_unregister ($name) { - $rg = ini_get('register_globals'); - if ( (float)substr(PHP_VERSION,0,3) < 4.1 && empty($rg)) { - global $HTTP_SESSION_VARS; + if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) { + global $HTTP_SESSION_VARS; unset($HTTP_SESSION_VARS["$name"]); } else { - session_unregister("$name"); + unset($_SESSION["$name"]); + } +} +function sqsession_is_registered ($name) { + $test_name = &$name; + $result = false; + if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) { + global $HTTP_SESSION_VARS; + if (isset($HTTP_SESSION_VARS[$test_name])) { + $result = true; + } + } + else { + if (isset($_SESSION[$test_name])) { + $result = true; + } } + return $result; } + /** * Search for the var $name in $_SESSION, $_POST, $_GET * (in that order) and register it as a global var. diff --git a/functions/imap_messages.php b/functions/imap_messages.php index 3b52743e..859702b5 100755 --- a/functions/imap_messages.php +++ b/functions/imap_messages.php @@ -105,7 +105,7 @@ function sqimap_get_sort_order ($imap_stream, $sort, $mbxresponse) { $internal_date_sort, $server_sort_array, $sent_folder, $mailbox, $uid_support; - if (session_is_registered('server_sort_array')) { + if (sqsession_is_registered('server_sort_array')) { sqsession_unregister('server_sort_array'); } @@ -180,7 +180,7 @@ function sqimap_get_sort_order ($imap_stream, $sort, $mbxresponse) { function sqimap_get_php_sort_order ($imap_stream, $mbxresponse) { global $uid_support; - if (session_is_registered('php_sort_array')) { + if (sqsession_is_registered('php_sort_array')) { sqsession_unregister('php_sort_array'); } @@ -319,10 +319,10 @@ function get_parent_level ($imap_stream) { function get_thread_sort ($imap_stream) { global $thread_new, $sort_by_ref, $default_charset, $server_sort_array, $uid_support; - if (session_is_registered('thread_new')) { + if (sqsession_is_registered('thread_new')) { sqsession_unregister('thread_new'); } - if (session_is_registered('server_sort_array')) { + if (sqsession_is_registered('server_sort_array')) { sqsession_unregister('server_sort_array'); } $sid = sqimap_session_id($uid_support); diff --git a/functions/prefs.php b/functions/prefs.php index 4445f53b..c37748bd 100644 --- a/functions/prefs.php +++ b/functions/prefs.php @@ -22,7 +22,7 @@ if (isset($_SESSION['prefs_are_cached'])) { $rg = ini_get('register_globals'); -if ( !session_is_registered('prefs_are_cached') || +if ( !sqsession_is_registered('prefs_are_cached') || !isset( $prefs_cache) || !is_array( $prefs_cache) || substr( phpversion(), 0, 3 ) == '4.1' || diff --git a/src/compose.php b/src/compose.php index d4b3d7c1..c05cbc52 100644 --- a/src/compose.php +++ b/src/compose.php @@ -190,7 +190,7 @@ function getforwardHeader($orig_header) { */ //$session_expired = false; sqsession_unregister('session_expired_post'); -if (false && session_is_registered('session_expired_post')) { +if (false && sqsession_is_registered('session_expired_post')) { global $session_expired_post, $session_expired; /* * extra check for username so we don't display previous post data from diff --git a/src/redirect.php b/src/redirect.php index 0b47fd2d..14cbca25 100644 --- a/src/redirect.php +++ b/src/redirect.php @@ -82,7 +82,7 @@ if (!isset($login_username)) { exit; } -if (!session_is_registered('user_is_logged_in')) { +if (!sqsession_is_registered('user_is_logged_in')) { do_hook ('login_before'); $onetimepad = OneTimePadCreate(strlen($secretkey)); diff --git a/src/right_main.php b/src/right_main.php index 8470069f..5dcaf7a3 100644 --- a/src/right_main.php +++ b/src/right_main.php @@ -198,18 +198,18 @@ if (! isset($use_mailbox_cache)) { $use_mailbox_cache = 0; } -if ($use_mailbox_cache && session_is_registered('msgs')) { +if ($use_mailbox_cache && sqsession_is_registered('msgs')) { showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, $use_mailbox_cache); } else { - if (session_is_registered('msgs')) { + if (sqsession_is_registered('msgs')) { unset($msgs); } - if (session_is_registered('msort')) { + if (sqsession_is_registered('msort')) { unset($msort); } - if (session_is_registered('numMessages')) { + if (sqsession_is_registered('numMessages')) { unset($numMessages); } @@ -219,12 +219,12 @@ if ($use_mailbox_cache && session_is_registered('msgs')) { $startMessage, $sort, $color, $show_num, $use_mailbox_cache); - if (session_is_registered('msgs') && isset($msgs)) { + if (sqsession_is_registered('msgs') && isset($msgs)) { sqsession_register($msgs, 'msgs'); $_SESSION['msgs'] = $msgs; } - if (session_is_registered('msort') && isset($msort)) { + if (sqsession_is_registered('msort') && isset($msort)) { sqsession_register($msort, 'msort'); $_SESSION['msort'] = $msort; } diff --git a/themes/random.php b/themes/random.php index 765da388..c31ddaf1 100755 --- a/themes/random.php +++ b/themes/random.php @@ -19,7 +19,7 @@ require_once(SM_PATH . 'functions/global.php'); global $theme, $random_theme_good_themes; -if (!session_is_registered('random_theme_good_theme')) { +if (!sqsession_is_registered('random_theme_good_theme')) { $good_themes = array(); foreach ($theme as $data) { if (substr($data['PATH'], -18) != '/themes/random.php') { -- 2.25.1