2 /************************************************************************
3 * MXChange v0.2.1 Start: 02/28/2009 *
4 * =============== Last change: 02/28/2009 *
6 * -------------------------------------------------------------------- *
7 * File : session-functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Session-relevant functions *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Sitzungsrelevante Funktionen *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
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;
45 // Trim value and session variable
46 $var = trim(SQL_ESCAPE($var)); $value = trim($value);
48 // Is the session variable set?
49 if (("".$value."" == "") && (isSessionVariableSet($var))) {
51 //* DEBUG: */ echo "UNSET:".$var."=".get_session($var)."<br />\n";
52 unset($_SESSION[$var]);
53 return session_unregister($var);
54 } elseif (("".$value."" != '') && (!isSessionVariableSet($var))) {
56 //* DEBUG: */ echo "SET:".$var."=".$value."<br />\n";
57 $_SESSION[$var] = $value;
58 return session_register($var);
59 } elseif (!empty($value)) {
61 //* DEBUG: */ echo "UPDATE:".$var."=".$value."<br />\n";
62 $_SESSION[$var] = $value;
66 // Ignored (but valid)
67 //* DEBUG: */ echo "IGNORED:".$var."=".$value."<br />\n";
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]));
77 // Returns wether the value of the session variable or NULL if not set
78 function get_session ($var) {
79 // Default is not found! ;-)
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]);
93 $GLOBALS['cache_array']['session'][$var] = $value;
100 // Destroy user session
101 function destroy_user_session () {
103 $GLOBALS['userid'] = 0;
105 // Remove all user data from session
106 return ((set_session('userid', "")) && (set_session('u_hash', "")));
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' , "");
117 // Destroy session and return status
119 return session_destroy();
122 // All fine if we shall not really destroy the session