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, 2010 by Mailer Developer Team *
20 * For more information visit: http://www.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()) return true;
48 // Trim value and session variable
49 $var = trim(secureString($var)); $value = trim($value);
51 // Is the session variable set?
52 if (('' . $value . '' == '') && (isSessionVariableSet($var))) {
54 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'UNSET:' . $var . '=' . getSession($var));
55 unset($GLOBALS['_SESSION'][$var]);
56 if (phpversion() >= '5.3.1') {
57 // session_unregister() is deprecated as of 5.3.1
60 // PHP version < 5.3.1
61 return session_unregister($var);
63 } elseif (('' . $value . '' != '') && (!isSessionVariableSet($var))) {
65 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SET:' . $var . '=' . $value);
66 $GLOBALS['_SESSION'][$var] = $value;
67 if (phpversion() >= '5.3.1') {
68 // session_unregister() is deprecated as of 5.3.1
71 // PHP version < 5.3.1
72 return session_register($var);
74 } elseif (!empty($value)) {
76 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'UPDATE:' . $var . '=' . $value);
77 $GLOBALS['_SESSION'][$var] = $value;
81 // Ignored (but valid)
82 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'IGNORED:' . $var . '=' . $value);
86 // Check wether a session variable is set
87 function isSessionVariableSet ($var) {
88 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "var={$var}");
89 return (isset($GLOBALS['_SESSION'][$var]));
92 // Returns wether the value of the session variable or NULL if not set
93 function getSession ($var) {
94 // Default is not found! ;-)
97 // Is the variable there?
98 if (isSessionVariableSet($var)) {
99 // Then get it secured!
100 $value = SQL_ESCAPE($GLOBALS['_SESSION'][$var]);
104 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $var . '=' . $value);
108 // Destroy user session
109 function destroyMemberSession () {
113 // Remove all user data from session
114 return ((setSession('userid', '')) && (setSession('u_hash', '')));
117 // Destroys the admin session
118 function destroyAdminSession ($destroy = true) {
119 // Kill maybe existing session variables including array elements
120 setSession('admin_id' , '');
121 setSession('admin_md5' , '');
122 setSession('admin_last', '');
124 // Destroy session and return status
126 return session_destroy();
129 // All fine if we shall not really destroy the session