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 - 2011 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()) return true;
48 // Trim value and session variable
49 $var = trim(secureString($var));
50 $value = trim($value);
52 // Is the session variable set?
53 if (('' . $value . '' == '') && (isSessionVariableSet($var))) {
55 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'UNSET:' . $var . '=' . getSession($var));
56 unset($GLOBALS['_SESSION'][$var]);
57 if (phpversion() >= '5.3.1') {
58 // session_unregister() is deprecated as of 5.3.1
61 // PHP version < 5.3.1
62 return session_unregister($var);
64 } elseif (('' . $value . '' != '') && (!isSessionVariableSet($var))) {
66 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SET:' . $var . '=' . $value);
67 $GLOBALS['_SESSION'][$var] = $value;
68 if (phpversion() >= '5.3.1') {
69 // session_unregister() is deprecated as of 5.3.1
72 // PHP version < 5.3.1
73 return session_register($var);
75 } elseif (!empty($value)) {
77 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'UPDATE:' . $var . '=' . $value);
78 $GLOBALS['_SESSION'][$var] = $value;
82 // Ignored (but valid)
83 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'IGNORED:' . $var . '=' . $value);
87 // Check wether a session variable is set
88 function isSessionVariableSet ($var) {
89 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'var=' . $var . ' set in session');
90 return (isset($GLOBALS['_SESSION'][$var]));
93 // Returns wether the value of the session variable or NULL if not set
94 function getSession ($var) {
95 // Default is not found ;-)
98 // Is the variable there?
99 if (isSessionVariableSet($var)) {
100 // Then get it secured!
101 $value = SQL_ESCAPE($GLOBALS['_SESSION'][$var]);
105 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $var . '=' . $value);
109 // Destroy user session
110 function destroyMemberSession () {
114 // Remove all user data from session
115 return ((setSession('userid', '')) && (setSession('u_hash', '')));
118 // Destroys the admin session
119 function destroyAdminSession ($destroy = true) {
120 // Kill maybe existing session variables including array elements
125 // Destroy session if requested and return status
126 if ($destroy === true) {
127 return session_destroy();
130 // All fine if we shall not really destroy the session