0.0.0 shall be our first version
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.mxchange.org                  *
21  *                                                                      *
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.                                  *
26  *                                                                      *
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.                         *
31  *                                                                      *
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,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 }
42
43 // Unset/set session variables
44 function setSession ($var, $value) {
45         // Abort in CSS mode here
46         if (isCssOutputMode()) return true;
47
48         // Trim value and session variable
49         $var   = trim(secureString($var));
50         $value = trim($value);
51
52         // Is the session variable set?
53         if (('' . $value . '' == '') && (isSessionVariableSet($var))) {
54                 // Remove the session
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
59                         return true;
60                 } else {
61                         // PHP version < 5.3.1
62                         return session_unregister($var);
63                 }
64         } elseif (('' . $value . '' != '') && (!isSessionVariableSet($var))) {
65                 // Set session
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
70                         return true;
71                 } else {
72                         // PHP version < 5.3.1
73                         return session_register($var);
74                 }
75         } elseif (!empty($value)) {
76                 // Update session
77                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'UPDATE:' . $var . '=' . $value);
78                 $GLOBALS['_SESSION'][$var] = $value;
79                 return true;
80         }
81
82         // Ignored (but valid)
83         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'IGNORED:' . $var . '=' . $value);
84         return true;
85 }
86
87 // Check wether a session variable is set
88 function isSessionVariableSet ($var) {
89         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "var={$var}");
90         return (isset($GLOBALS['_SESSION'][$var]));
91 }
92
93 // Returns wether the value of the session variable or NULL if not set
94 function getSession ($var) {
95         // Default is not found ;-)
96         $value = null;
97
98         // Is the variable there?
99         if (isSessionVariableSet($var)) {
100                 // Then  get it secured!
101                 $value = SQL_ESCAPE($GLOBALS['_SESSION'][$var]);
102         } // END - if
103
104         // Return the value
105         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $var . '=' . $value);
106         return $value;
107 }
108
109 // Destroy user session
110 function destroyMemberSession () {
111         // Reset userid
112         initMemberId();
113
114         // Remove all user data from session
115         return ((setSession('userid', '')) && (setSession('u_hash', '')));
116 }
117
118 // Destroys the admin session
119 function destroyAdminSession ($destroy = true) {
120         // Kill maybe existing session variables including array elements
121         setAdminId(0);
122         setAdminMd5('');
123         setAdminLast('');
124
125         // Destroy session if requested and return status
126         if ($destroy === true) {
127                 return session_destroy();
128         } // END - if
129
130         // All fine if we shall not really destroy the session
131         return true;
132 }
133
134 // [EOF]
135 ?>