Huge script change, see http://forum.mxchange.org/topic-458.html for details:
[mailer.git] / inc / session-functions.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 }
43
44 // Unset/set session variables
45 function setSession ($var, $value) {
46         // Abort in CSS mode here
47         if (getOutputMode() == 1) return true;
48
49         // Trim value and session variable
50         $var = trim(SQL_ESCAPE($var)); $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                 return session_unregister($var);
58         } elseif (("".$value."" != '') && (!isSessionVariableSet($var))) {
59                 // Set session
60                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "SET:".$var.'='.$value);
61                 $GLOBALS['_SESSION'][$var] =  $value;
62                 return session_register($var);
63         } elseif (!empty($value)) {
64                 // Update session
65                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "UPDATE:".$var.'='.$value);
66                 $GLOBALS['_SESSION'][$var] = $value;
67                 return true;
68         }
69
70         // Ignored (but valid)
71         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "IGNORED:".$var.'='.$value);
72         return true;
73 }
74
75 // Check wether a session variable is set
76 function isSessionVariableSet ($var) {
77         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "var={$var}");
78         return (isset($GLOBALS['_SESSION'][$var]));
79 }
80
81 // Returns wether the value of the session variable or NULL if not set
82 function getSession ($var) {
83         // Default is not found! ;-)
84         $value = null;
85
86         // Is the variable there?
87         if (isSessionVariableSet($var)) {
88                 // Then  get it secured!
89                 $value = SQL_ESCAPE($GLOBALS['_SESSION'][$var]);
90         } // END - if
91
92         // Return the value
93         return $value;
94 }
95
96 // Destroy user session
97 function destroyUserSession () {
98         // Reset userid
99         setUserId(0);
100
101         // Remove all user data from session
102         return ((setSession('userid', '')) && (setSession('u_hash', '')));
103 }
104
105 // Destroys the admin session
106 function destroyAdminSession ($destroy = true) {
107         // Kill maybe existing session variables including array elements
108         setSession('admin_login', '');
109         setSession('admin_md5'  , '');
110         setSession('admin_last' , '');
111         setSession('admin_to'   , '');
112
113         // Destroy session and return status
114         if ($destroy) {
115                 return session_destroy();
116         } // END - if
117
118         // All fine if we shall not really destroy the session
119         return true;
120 }
121
122 // [EOF]
123 ?>