Debug code commented out
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
37         require($INC);
38 }
39
40 // Unset/set session variables
41 function set_session ($var, $value) {
42         // Abort in CSS mode here
43         if ($GLOBALS['output_mode'] == 1) return true;
44
45         // Trim value and session variable
46         $var = trim(SQL_ESCAPE($var)); $value = trim($value);
47
48         // Is the session variable set?
49         if (("".$value."" == "") && (isSessionVariableSet($var))) {
50                 // Remove the session
51                 //* DEBUG: */ echo "UNSET:".$var."=".get_session($var)."<br />\n";
52                 unset($_SESSION[$var]);
53                 return session_unregister($var);
54         } elseif (("".$value."" != '') && (!isSessionVariableSet($var))) {
55                 // Set session
56                 //* DEBUG: */ echo "SET:".$var."=".$value."<br />\n";
57                 $_SESSION[$var] =  $value;
58                 return session_register($var);
59         } elseif (!empty($value)) {
60                 // Update session
61                 //* DEBUG: */ echo "UPDATE:".$var."=".$value."<br />\n";
62                 $_SESSION[$var] = $value;
63                 return true;
64         }
65
66         // Ignored (but valid)
67         //* DEBUG: */ echo "IGNORED:".$var."=".$value."<br />\n";
68         return true;
69 }
70
71 // Check wether a session variable is set
72 function isSessionVariableSet ($var) {
73         //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):var={$var}<br />\n";
74         return (isset($_SESSION[$var]));
75 }
76
77 // Returns wether the value of the session variable or NULL if not set
78 function get_session ($var) {
79         // Default is not found! ;-)
80         $value = null;
81
82         // Is the variable there or cached values?
83         if (isset($GLOBALS['cache_array']['session'][$var])) {
84                 // Get cached value (skips a lot SQL_ESCAPE() calles!
85                 //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): ".$var."-CACHE!<br />\n";
86                 $value = $GLOBALS['cache_array']['session'][$var];
87         } elseif (isSessionVariableSet($var)) {
88                 // Then  get it secured!
89                 //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): ".$var."-RESOLVE!<br />\n";
90                 $value = SQL_ESCAPE($_SESSION[$var]);
91
92                 // Cache the value
93                 $GLOBALS['cache_array']['session'][$var] = $value;
94         } // END - if
95
96         // Return the value
97         return $value;
98 }
99
100 // Destroy user session
101 function destroy_user_session () {
102         // Reset userid
103         $GLOBALS['userid'] = 0;
104
105         // Remove all user data from session
106         return ((set_session('userid', "")) && (set_session('u_hash', "")));
107 }
108
109 // Destroys the admin session
110 function destroyAdminSession ($destroy = true) {
111         // Kill maybe existing session variables including array elements
112         set_session('admin_login', "");
113         set_session('admin_md5'  , "");
114         set_session('admin_last' , "");
115         set_session('admin_to'   , "");
116
117         // Destroy session and return status
118         if ($destroy) {
119                 return session_destroy();
120         } // END - if
121
122         // All fine if we shall not really destroy the session
123         return true;
124 }
125
126 // [EOF]
127 ?>