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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
44 // Unset/set session variables
45 function setSession ($var, $value) {
46 // Abort in CSS mode here
47 if (getOutputMode() == 1) return true;
49 // Trim value and session variable
50 $var = trim(SQL_ESCAPE($var)); $value = trim($value);
52 // Is the session variable set?
53 if ((''.$value.'' == '') && (isSessionVariableSet($var))) {
55 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "UNSET:".$var.'='.getSession($var));
56 unset($GLOBALS['_SESSION'][$var]);
57 return session_unregister($var);
58 } elseif (("".$value."" != '') && (!isSessionVariableSet($var))) {
60 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "SET:".$var.'='.$value);
61 $GLOBALS['_SESSION'][$var] = $value;
62 return session_register($var);
63 } elseif (!empty($value)) {
65 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "UPDATE:".$var.'='.$value);
66 $GLOBALS['_SESSION'][$var] = $value;
70 // Ignored (but valid)
71 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "IGNORED:".$var.'='.$value);
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]));
81 // Returns wether the value of the session variable or NULL if not set
82 function getSession ($var) {
83 // Default is not found! ;-)
86 // Is the variable there?
87 if (isSessionVariableSet($var)) {
88 // Then get it secured!
89 $value = SQL_ESCAPE($GLOBALS['_SESSION'][$var]);
96 // Destroy user session
97 function destroyMemberSession () {
101 // Remove all user data from session
102 return ((setSession('userid', '')) && (setSession('u_hash', '')));
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' , '');
113 // Destroy session and return status
115 return session_destroy();
118 // All fine if we shall not really destroy the session