* @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 = ''.$result['nick'].'';
break;
}
case '2':
{
$user_color_name = ''.$result['nick'].'';
break;
}
}
$name .= ''.$user_color_name.', ';
}
}
else
{
$name = ''.$lng['empty'].'';
}
return array($name, @mysql_num_rows($query));
}
?>