<?php
|
|
/**
|
|
* @package Dynamic Script Forum
|
|
* @file includes/sessions.php
|
|
* @version 1.0.x, 30-07-2007, 11:41
|
|
* @copyright 2008(c) PioDer <[email protected]>
|
|
* @link http://pioder.gim2przemysl.int.pl/dsf.html
|
|
* @license GNU GPL v3
|
|
**/
|
|
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',time()+31104000);
|
|
}
|
|
if($_COOKIE['queries']>0)
|
|
{
|
|
setcookie('queries','0',time()+31104000);
|
|
$_COOKIE['uid']='0';
|
|
}
|
|
function sess_register($uid)
|
|
{
|
|
if ($uid>0)
|
|
{
|
|
sess_delete($uid);
|
|
$time = time();
|
|
$sql = "INSERT INTO ".SESSIONS_TABLE." VALUES ('', '".$_COOKIE[SESS_NAME]."','$uid','$time')";
|
|
$result = @mysql_fetch_array(DataBase::sql_query($sql,'GENERAL','Could not add new session.',true));
|
|
return $result;
|
|
}
|
|
}
|
|
function sess_delete_old()
|
|
{
|
|
$time = time();
|
|
$sql = "DELETE FROM ".SESSIONS_TABLE." WHERE time+129600<$time;";
|
|
DataBase::sql_query($sql, 'GENERAL','Could not delete session',true);
|
|
}
|
|
function sess_del_invalid()
|
|
{
|
|
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 = mysql_fetch_array($query);
|
|
$result = $result['session_id'];
|
|
if ($_COOKIE[SESS_NAME]!=$result)
|
|
{
|
|
$_SESSION['sessionid'] = '0';
|
|
$_SESSION['uid'] = '0';
|
|
}
|
|
}
|
|
}
|
|
function sess_delete($uid)
|
|
{
|
|
$time = time();
|
|
$sql = "DELETE FROM ".SESSIONS_TABLE." WHERE u_id='$uid'";
|
|
$result = @mysql_fetch_array(DataBase::sql_query($sql, 'GENERAL','Could not delete session',true));
|
|
$_SESSION['sessionid']='0';
|
|
return $result['count'];
|
|
}
|
|
function sess_view()
|
|
{
|
|
global $lng;
|
|
global $user;
|
|
global $forum_config;
|
|
$name = '';
|
|
$time = 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 (@mysql_num_rows($query)>0)
|
|
{
|
|
while($result = @mysql_fetch_array($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, @mysql_num_rows($query));
|
|
}
|
|
?>
|