8f1669f5a35cea9e09a2c1c2ceddf5d233ef1b4a
[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                 return session_unregister($var);
59         } elseif (('' . $value . '' != '') && (!isSessionVariableSet($var))) {
60                 // Set session
61                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SET:' . $var . '=' . $value);
62                 $GLOBALS['_SESSION'][$var] =  $value;
63                 return session_register($var);
64         } elseif (!empty($value)) {
65                 // Update session
66                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'UPDATE:' . $var . '=' . $value);
67                 $GLOBALS['_SESSION'][$var] = $value;
68                 return true;
69         }
70
71         // Ignored (but valid)
72         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'IGNORED:' . $var . '=' . $value);
73         return true;
74 }
75
76 // Check wether a session variable is set
77 function isSessionVariableSet ($var) {
78         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "var={$var}");
79         return (isset($GLOBALS['_SESSION'][$var]));
80 }
81
82 // Returns wether the value of the session variable or NULL if not set
83 function getSession ($var) {
84         // Default is not found! ;-)
85         $value = null;
86
87         // Is the variable there?
88         if (isSessionVariableSet($var)) {
89                 // Then  get it secured!
90                 $value = SQL_ESCAPE($GLOBALS['_SESSION'][$var]);
91         } // END - if
92
93         // Return the value
94         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $var . '=' . $value);
95         return $value;
96 }
97
98 // Destroy user session
99 function destroyMemberSession () {
100         // Reset userid
101         initMemberId();
102
103         // Remove all user data from session
104         return ((setSession('userid', '')) && (setSession('u_hash', '')));
105 }
106
107 // Destroys the admin session
108 function destroyAdminSession ($destroy = true) {
109         // Kill maybe existing session variables including array elements
110         setSession('admin_login', '');
111         setSession('admin_md5'  , '');
112         setSession('admin_last' , '');
113
114         // Destroy session and return status
115         if ($destroy) {
116                 return session_destroy();
117         } // END - if
118
119         // All fine if we shall not really destroy the session
120         return true;
121 }
122
123 // [EOF]
124 ?>