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 - 2008 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')) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
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;
50 // Trim value and session variable
51 $var = trim(SQL_ESCAPE($var)); $value = trim($value);
53 // Is the session variable set?
54 if (("".$value."" == "") && (isSessionVariableSet($var))) {
56 //* DEBUG: */ echo "UNSET:".$var."=".get_session($var)."<br />\n";
57 unset($_SESSION[$var]);
58 return session_unregister($var);
59 } elseif (("".$value."" != '') && (!isSessionVariableSet($var))) {
61 //* DEBUG: */ echo "SET:".$var."=".$value."<br />\n";
62 $_SESSION[$var] = $value;
63 return session_register($var);
64 } elseif (!empty($value)) {
66 //* DEBUG: */ echo "UPDATE:".$var."=".$value."<br />\n";
67 $_SESSION[$var] = $value;
71 // Ignored (but valid)
72 //* DEBUG: */ echo "IGNORED:".$var."=".$value."<br />\n";
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]));
82 // Returns wether the value of the session variable or NULL if not set
83 function get_session ($var) {
84 // Default is not found! ;-)
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]);
98 $GLOBALS['cache_array']['session'][$var] = $value;
105 // Destroy user session
106 function destroy_user_session () {
110 // Remove all user data from session
111 return ((set_session('userid', "")) && (set_session('u_hash', "")));
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' , "");
122 // Destroy session and return status
124 return session_destroy();
127 // All fine if we shall not really destroy the session