2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 02/28/2009 *
4 * =================== Last change: 02/28/2009 *
6 * -------------------------------------------------------------------- *
7 * File : session-functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Session-relevant functions *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Sitzungsrelevante Funktionen *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Unset/set session variables
44 function setSession ($var, $value) {
45 // Abort in CSS mode here
46 if (isCssOutputMode()) {
50 // Trim value and session variable
51 $var = trim(secureString($var));
52 $value = trim($value);
54 // Is the session variable set?
55 if (('' . $value . '' == '') && (isSessionVariableSet($var))) {
57 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'UNSET:' . $var . '=' . getSession($var));
58 unset($GLOBALS['_SESSION'][$var]);
59 if (isPhpVersionEqualNewer('5.3.0')) {
60 // session_unregister() is deprecated as of 5.3.0
63 // PHP version < 5.3.0
64 return session_unregister($var);
66 } elseif (('' . $value . '' != '') && (!isSessionVariableSet($var))) {
68 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SET:' . $var . '=' . $value);
69 $GLOBALS['_SESSION'][$var] = $value;
70 if (isPhpVersionEqualNewer('5.3.0')) {
71 // session_unregister() is deprecated as of 5.3.0
74 // PHP version < 5.3.0
75 return session_register($var);
77 } elseif (!empty($value)) {
79 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'UPDATE:' . $var . '=' . $value);
80 $GLOBALS['_SESSION'][$var] = $value;
84 // Ignored (but valid)
85 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'IGNORED:' . $var . '=' . $value);
89 // Check whether a session variable is set
90 function isSessionVariableSet ($var) {
91 // Warning: DO NOT call logDebugMessage() from here, this will cause an endless loop
92 return (isset($GLOBALS['_SESSION'][$var]));
95 // Returns whether the value of the session variable or NULL if not set
96 function getSession ($var) {
97 // Default is not found ;-)
100 // Is the variable there?
101 if (isSessionVariableSet($var)) {
102 // Then get it secured!
103 $value = SQL_ESCAPE($GLOBALS['_SESSION'][$var]);
107 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $var . '=' . $value);
111 // Get whole session array
112 function getSessionArray () {
114 return $GLOBALS['_SESSION'];
117 // Destroy user session
118 function destroyMemberSession ($destroy = FALSE) {
122 // Remove all user data from session
123 if ($destroy === TRUE) {
124 // Destroy whole session
125 return destroySession();
127 return ((setSession('userid', '')) && (setSession('u_hash', '')));
131 // Destroys the admin session
132 function destroyAdminSession ($destroy = FALSE) {
133 // Kill maybe existing session variables including array elements
138 // Set cache to FALSE
139 $GLOBALS['isAdmin'] = FALSE;
141 // Destroy session if requested and return status
142 if ($destroy === TRUE) {
143 return destroySession();
146 // All fine if the session shall not really be destroyed
150 // Destroys session and resets some "caches"
151 function destroySession () {
153 unset($GLOBALS['isSessionValid']);
156 return session_destroy();
159 // Checks whether the session is valid
160 function isSessionValid () {
162 if (!isset($GLOBALS[__FUNCTION__])) {
164 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['valid_session'])) && ($GLOBALS['valid_session'] === TRUE) && (isset($_COOKIE[session_name()])));
168 return $GLOBALS[__FUNCTION__];
171 // Checks whether all given session data is set
172 function isSessionDataSet ($sessionData) {
177 foreach ($sessionData as $key) {
178 // Is this element set?
179 $isset = (($isset) && (isSessionVariableSet($key)));