- <?php
- /**
- * @package uForum
- * @file includes/sessions.php
- * @version $Id$
- * @copyright 2007-2010 (c) PioDer <pioder@wp.pl>
- * @link http://www.pioder.pl/
- * @license see LICENSE.txt
- **/
- if ( !defined('IN_uF') )
- {
- die('Hacking attempt');
- }
-
- //set global sessions options
- ini_set('session.cookie_lifetime',SESSION_LIFETIME);
- ini_set('session.name',SESS_NAME); //1,5 day
- if ((isset($_COOKIE[SESS_NAME])) && (empty($_SESSION['uid'])))
- {
- session_id($_COOKIE[SESS_NAME]);
- }
- session_start(); //starting session
-
- //check, for empty session values and set
- if (empty($_SESSION['uid']))
- {
- $_SESSION['uid']='0';
- }
-
- if (empty($_SESSION['login_on']))
- {
- $_SESSION['login_on']='0';
- }
-
- if (empty($_SESSION['sessionid']))
- {
- $_SESSION['sessionid']='0';
- }
-
- if (empty($_COOKIE['queries']))
- {
- $_COOKIE['queries']=0;
- setcookie('queries','0',$_SERVER['REQUEST_TIME']+31104000);
- }
-
- if($_COOKIE['queries']>0)
- {
- setcookie('queries','0',$_SERVER['REQUEST_TIME']+31104000);
- $_COOKIE['uid']='0';
- }
-
- function SessRegister()
- {
- $uid = $_SESSION['uid'];
-
- if ($uid>0)
- {
- SessDelete($uid);
- $time = $_SERVER['REQUEST_TIME'];
- $sql = "INSERT INTO ".SESSIONS_TABLE." VALUES ('', '".$_COOKIE[SESS_NAME]."','$uid','$time')";
- $query = DataBase::sql_query($sql,GENERAL,'Could not add new session.',true);
- if (DataBase::num_rows($query)>0)
- {
- $result = DataBase::fetch();
- return $result;
- }
- else
- {
- return false;
- }
- }
- }
-
- function SessDeleteOld()
- {
- $time = $_SERVER['REQUEST_TIME'];
- $sql = "DELETE FROM ".SESSIONS_TABLE." WHERE time+129600<$time;";
- DataBase::sql_query($sql, GENERAL,'Could not delete session',true);
- }
-
- function SessDelInvalid()
- {
- if ($_SESSION['uid']>0)
- {
- $sql = "SELECT `session_id`, `u_id` FROM ".SESSIONS_TABLE." WHERE `u_id`='".$_SESSION['uid']."'";
- $query = DataBase::sql_query($sql,GENERAL,'Could not obtain session information',true);
- $result = DataBase::fetch($query);
- $result = $result['session_id'];
- if ($_COOKIE[SESS_NAME]!=$result)
- {
- $_SESSION['sessionid'] = '0';
- $_SESSION['uid'] = '0';
- }
- }
- }
-
- function SessDelete($uid)
- {
- $time = $_SERVER['REQUEST_TIME'];
- $sql = "DELETE FROM ".SESSIONS_TABLE." WHERE u_id='$uid'";
- $query = DataBase::sql_query($sql, GENERAL,'Could not delete session',true);
- if (DataBase::num_rows($query)>0)
- {
- $result = DataBase::fetch($query);
- $_SESSION['sessionid']='0';
- return $result['count'];
- }
- }
-
- function SessView()
- {
- global $lng;
- global $user;
- global $forum_config;
- $name = '';
- $time = $_SERVER['REQUEST_TIME'];
- $sql = "SELECT ".SESSIONS_TABLE.".*, ".USERS_TABLE.".*, ".SESSIONS_TABLE.".u_id AS u_id FROM ".SESSIONS_TABLE." LEFT JOIN ".USERS_TABLE." ON ".SESSIONS_TABLE.".u_id = ".USERS_TABLE.".u_id WHERE time+1250>$time;";
- $query = DataBase::sql_query($sql, GENERAL,'Could not obtain sessions information.');
- if (DataBase::num_rows($query)>0)
- {
- while($result = DataBase::fetch($query))
- {
- $uid = $result['u_id'];
- switch($result['rank'])
- {
- case '0':
- {
- $user_color_name = $result['nick'];
- break;
- }
- case '1':
- {
- $user_color_name = '<font color="'.$forum_config['color_mod'].'"><b>'.$result['nick'].'</b></font>';
- break;
- }
- case '2':
- {
- $user_color_name = '<font color="'.$forum_config['color_admin'].'"><b>'.$result['nick'].'</b></font>';
- break;
- }
- }
- $name .= '<a href="user.php?id='.$uid.'" class="fstandard">'.$user_color_name.'</a>, ';
- }
- }
- else
- {
- $name = '<span class="userlink">'.$lng['empty'].'</span>';
- }
- return array($name, DataBase::num_rows($query));
- }
- ?>
|