X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fglobal.php;h=673008e5691df50173023045b53261b5ee0f673e;hb=793ee86a81a9465cb8d942e92f1cc12e9d15b834;hp=e01cbb6c4a8585756e184421de0a7974985c0289;hpb=f79c19a48bf98f3b990aeca732c911b556d8c7cd;p=squirrelmail.git diff --git a/functions/global.php b/functions/global.php index e01cbb6c..673008e5 100644 --- a/functions/global.php +++ b/functions/global.php @@ -1,9 +1,9 @@ 0) { foreach ($array as $index=>$value) { @@ -115,48 +116,49 @@ function sqstripslashes(&$array) { } } +/** + * Add a variable to the session. + * @param mixed $var the variable to register + * @param string $name the name to refer to this variable + * @return void + */ function sqsession_register ($var, $name) { sqsession_is_active(); - if ( !check_php_version(4,1) ) { - global $HTTP_SESSION_VARS; - $HTTP_SESSION_VARS[$name] = $var; - } - else { - $_SESSION["$name"] = $var; - } + $_SESSION["$name"] = $var; + session_register("$name"); } +/** + * Delete a variable from the session. + * @param string $name the name of the var to delete + * @return void + */ function sqsession_unregister ($name) { sqsession_is_active(); - if ( !check_php_version(4,1) ) { - global $HTTP_SESSION_VARS; - unset($HTTP_SESSION_VARS[$name]); - } - else { - unset($_SESSION[$name]); - } + unset($_SESSION[$name]); + session_unregister("$name"); } +/** + * Checks to see if a variable has already been registered + * in the session. + * @param string $name the name of the var to check + * @return bool whether the var has been registered + */ function sqsession_is_registered ($name) { $test_name = &$name; $result = false; - if ( !check_php_version(4,1) ) { - global $HTTP_SESSION_VARS; - if (isset($HTTP_SESSION_VARS[$test_name])) { - $result = true; - } - } - else { - if (isset($_SESSION[$test_name])) { - $result = true; - } + + if (isset($_SESSION[$test_name])) { + $result = true; } + return $result; } @@ -167,6 +169,7 @@ define('SQ_POST',2); define('SQ_SESSION',3); define('SQ_COOKIE',4); define('SQ_SERVER',5); +define('SQ_FORM',6); /** * Search for the var $name in $_SESSION, $_POST, $_GET, @@ -184,22 +187,13 @@ define('SQ_SERVER',5); * sqgetGlobalVar('username',$username,SQ_SESSION); * -- no quotes around last param! * - * Returns FALSE if variable is not found. - * Returns TRUE if it is. + * @param string name the name of the var to search + * @param mixed value the variable to return + * @param int search constant defining where to look + * @return bool whether variable is found. */ function sqgetGlobalVar($name, &$value, $search = SQ_INORDER) { - if ( !check_php_version(4,1) ) { - global $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS, - $HTTP_SERVER_VARS, $HTTP_SESSION_VARS; - - $_COOKIE =& $HTTP_COOKIE_VARS; - $_GET =& $HTTP_GET_VARS; - $_POST =& $HTTP_POST_VARS; - $_SERVER =& $HTTP_SERVER_VARS; - $_SESSION =& $HTTP_SESSION_VARS; - } - /* NOTE: DO NOT enclose the constants in the switch statement with quotes. They are constant values, enclosing them in quotes will cause them to evaluate @@ -209,7 +203,7 @@ function sqgetGlobalVar($name, &$value, $search = SQ_INORDER) { so that if a valid value isn't specified, all three arrays will be searched. */ default: - case SQ_INORDER: + case SQ_INORDER: // check session, post, get case SQ_SESSION: if( isset($_SESSION[$name]) ) { $value = $_SESSION[$name]; @@ -217,6 +211,7 @@ function sqgetGlobalVar($name, &$value, $search = SQ_INORDER) { } elseif ( $search == SQ_SESSION ) { break; } + case SQ_FORM: // check post, get case SQ_POST: if( isset($_POST[$name]) ) { $value = $_POST[$name]; @@ -247,6 +242,10 @@ function sqgetGlobalVar($name, &$value, $search = SQ_INORDER) { return FALSE; } +/** + * Deletes an existing session, more advanced than the standard PHP + * session_destroy(), it explicitly deletes the cookies and global vars. + */ function sqsession_destroy() { /* @@ -268,18 +267,13 @@ function sqsession_destroy() { $sessid = session_id(); if (!empty( $sessid )) { - if ( !check_php_version(4,1) ) { - global $HTTP_SESSION_VARS; - $HTTP_SESSION_VARS = array(); - } else { - $_SESSION = array(); - } + $_SESSION = array(); @session_destroy(); } } -/* +/** * Function to verify a session has been started. If it hasn't * start a session up. php.net doesn't tell you that $_SESSION * (even though autoglobal), is not created unless a session is @@ -287,7 +281,7 @@ function sqsession_destroy() { */ function sqsession_is_active() { - + $sessid = session_id(); if ( empty( $sessid ) ) { session_start();