Fixed logfile writing in installation phase, .revision is now ignored
[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:: 856                                                    $ *
14  * $Date:: 2009-03-06 20:24:32 +0100 (Fr, 06. Mär 2009)              $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author:: stelzi                                                   $ *
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 - 2008 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         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
42         require($INC);
43 }
44
45 // Unset/set session variables
46 function set_session ($var, $value) {
47         // Abort in CSS mode here
48         if ($GLOBALS['output_mode'] == 1) return true;
49
50         // Trim value and session variable
51         $var = trim(SQL_ESCAPE($var)); $value = trim($value);
52
53         // Is the session variable set?
54         if (("".$value."" == "") && (isSessionVariableSet($var))) {
55                 // Remove the session
56                 //* DEBUG: */ echo "UNSET:".$var."=".get_session($var)."<br />\n";
57                 unset($_SESSION[$var]);
58                 return session_unregister($var);
59         } elseif (("".$value."" != '') && (!isSessionVariableSet($var))) {
60                 // Set session
61                 //* DEBUG: */ echo "SET:".$var."=".$value."<br />\n";
62                 $_SESSION[$var] =  $value;
63                 return session_register($var);
64         } elseif (!empty($value)) {
65                 // Update session
66                 //* DEBUG: */ echo "UPDATE:".$var."=".$value."<br />\n";
67                 $_SESSION[$var] = $value;
68                 return true;
69         }
70
71         // Ignored (but valid)
72         //* DEBUG: */ echo "IGNORED:".$var."=".$value."<br />\n";
73         return true;
74 }
75
76 // Check wether a session variable is set
77 function isSessionVariableSet ($var) {
78         //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):var={$var}<br />\n";
79         return (isset($_SESSION[$var]));
80 }
81
82 // Returns wether the value of the session variable or NULL if not set
83 function get_session ($var) {
84         // Default is not found! ;-)
85         $value = null;
86
87         // Is the variable there or cached values?
88         if (isset($GLOBALS['cache_array']['session'][$var])) {
89                 // Get cached value (skips a lot SQL_ESCAPE() calles!
90                 //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): ".$var."-CACHE!<br />\n";
91                 $value = $GLOBALS['cache_array']['session'][$var];
92         } elseif (isSessionVariableSet($var)) {
93                 // Then  get it secured!
94                 //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): ".$var."-RESOLVE!<br />\n";
95                 $value = SQL_ESCAPE($_SESSION[$var]);
96
97                 // Cache the value
98                 $GLOBALS['cache_array']['session'][$var] = $value;
99         } // END - if
100
101         // Return the value
102         return $value;
103 }
104
105 // Destroy user session
106 function destroy_user_session () {
107         // Reset userid
108         $GLOBALS['userid'] = 0;
109
110         // Remove all user data from session
111         return ((set_session('userid', "")) && (set_session('u_hash', "")));
112 }
113
114 // Destroys the admin session
115 function destroyAdminSession ($destroy = true) {
116         // Kill maybe existing session variables including array elements
117         set_session('admin_login', "");
118         set_session('admin_md5'  , "");
119         set_session('admin_last' , "");
120         set_session('admin_to'   , "");
121
122         // Destroy session and return status
123         if ($destroy) {
124                 return session_destroy();
125         } // END - if
126
127         // All fine if we shall not really destroy the session
128         return true;
129 }
130
131 // [EOF]
132 ?>