Rewrites/fixes for handling config entries in SQLs
[mailer.git] / inc / session-functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 02/28/2009 *
4  * ===================                          Last change: 02/28/2009 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : session-functions.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Session-relevant functions                       *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Sitzungsrelevante Funktionen                     *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 }
44
45 // Unset/set session variables
46 function setSession ($var, $value) {
47         // Abort in CSS mode here
48         if (getOutputMode() == 1) return true;
49
50         // Trim value and session variable
51         $var = trim(secureString($var)); $value = trim($value);
52
53         // Is the session variable set?
54         if (('' . $value . '' == '') && (isSessionVariableSet($var))) {
55                 // Remove the session
56                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'UNSET:' . $var . '=' . getSession($var));
57                 unset($GLOBALS['_SESSION'][$var]);
58                 if (phpversion() >= '5.3.1') {
59                         // session_unregister() is deprecated as of 5.3.1
60                         return true;
61                 } else {
62                         // PHP version < 5.3.1
63                         return session_unregister($var);
64                 }
65         } elseif (('' . $value . '' != '') && (!isSessionVariableSet($var))) {
66                 // Set session
67                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SET:' . $var . '=' . $value);
68                 $GLOBALS['_SESSION'][$var] =  $value;
69                 if (phpversion() >= '5.3.1') {
70                         // session_unregister() is deprecated as of 5.3.1
71                         return true;
72                 } else {
73                         // PHP version < 5.3.1
74                         return session_register($var);
75                 }
76         } elseif (!empty($value)) {
77                 // Update session
78                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'UPDATE:' . $var . '=' . $value);
79                 $GLOBALS['_SESSION'][$var] = $value;
80                 return true;
81         }
82
83         // Ignored (but valid)
84         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'IGNORED:' . $var . '=' . $value);
85         return true;
86 }
87
88 // Check wether a session variable is set
89 function isSessionVariableSet ($var) {
90         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "var={$var}");
91         return (isset($GLOBALS['_SESSION'][$var]));
92 }
93
94 // Returns wether the value of the session variable or NULL if not set
95 function getSession ($var) {
96         // Default is not found! ;-)
97         $value = null;
98
99         // Is the variable there?
100         if (isSessionVariableSet($var)) {
101                 // Then  get it secured!
102                 $value = SQL_ESCAPE($GLOBALS['_SESSION'][$var]);
103         } // END - if
104
105         // Return the value
106         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $var . '=' . $value);
107         return $value;
108 }
109
110 // Destroy user session
111 function destroyMemberSession () {
112         // Reset userid
113         initMemberId();
114
115         // Remove all user data from session
116         return ((setSession('userid', '')) && (setSession('u_hash', '')));
117 }
118
119 // Destroys the admin session
120 function destroyAdminSession ($destroy = true) {
121         // Kill maybe existing session variables including array elements
122         setSession('admin_login', '');
123         setSession('admin_md5'  , '');
124         setSession('admin_last' , '');
125
126         // Destroy session and return status
127         if ($destroy) {
128                 return session_destroy();
129         } // END - if
130
131         // All fine if we shall not really destroy the session
132         return true;
133 }
134
135 // [EOF]
136 ?>