forked from halo-battle/game
Version 1.7b
This commit is contained in:
parent
58928889ed
commit
8a8280758b
716 changed files with 4361 additions and 33524 deletions
146
onyx/session.class.php
Normal file
146
onyx/session.class.php
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
|
||||
class session {
|
||||
|
||||
var $xid;
|
||||
|
||||
var $level = 0;
|
||||
|
||||
var $cookie_name;
|
||||
|
||||
var $cookie;
|
||||
|
||||
var $values = array();
|
||||
|
||||
function clean()
|
||||
{
|
||||
global $config;
|
||||
|
||||
if($config['session']=='1')
|
||||
{
|
||||
$db = new bdd();
|
||||
$db->connexion();
|
||||
|
||||
#$db->control($config['db_prefix']."sessions");
|
||||
|
||||
$time = time()-$config['session_time'];
|
||||
$table = $config['db_prefix']."sessions";
|
||||
$db->query("DELETE FROM $table WHERE time < $time AND active = '1'");
|
||||
|
||||
$db->deconnexion();
|
||||
}
|
||||
}
|
||||
|
||||
function new_cookie()
|
||||
{
|
||||
global $config;
|
||||
|
||||
if($config['session']=='1')
|
||||
{
|
||||
$db = new bdd();
|
||||
$db->connexion();
|
||||
|
||||
$time = time();
|
||||
$xid = random();
|
||||
$sess_cookie = random(256);
|
||||
$ip = encode_ip();
|
||||
$table = $config['db_prefix']."sessions";
|
||||
$db->query("INSERT INTO $table(xid,session,time,ip,var_session,level,hash,active) VALUES('$xid','$sess_cookie','$time','$ip','','1','','0') ");
|
||||
$db->hash($table,"xid = '$xid'");
|
||||
|
||||
$this->xid = $xid;
|
||||
$this->cookie = $sess_cookie;
|
||||
|
||||
cookie((empty($this->cookie_name)?$config['session_name']:$this->cookie_name),$sess_cookie);
|
||||
|
||||
$db->deconnexion();
|
||||
}
|
||||
}
|
||||
|
||||
function load()
|
||||
{
|
||||
$this->clean();
|
||||
|
||||
global $config;
|
||||
|
||||
if($config['session']=='1')
|
||||
{
|
||||
|
||||
if($cookie = gpc($config['session_name'],'cookie'))
|
||||
{
|
||||
$db = new bdd();
|
||||
$db->connexion();
|
||||
|
||||
$db->escape($cookie);
|
||||
|
||||
$table = $config['db_prefix']."sessions";
|
||||
$db->check($table,"session = '$cookie'");
|
||||
$query = $db->unique_query("SELECT * FROM $table WHERE session='$cookie' AND active='1'");
|
||||
|
||||
if($db->num_rows == 1 && $query['ip'] == encode_ip())
|
||||
{
|
||||
|
||||
$this->xid = $query['xid'];
|
||||
$this->cookie = $query['session'];
|
||||
$this->level = $query['level'];
|
||||
$this->values = unserialize($query['var_session']);
|
||||
|
||||
cookie((empty($this->cookie_name)?$config['session_name']:$this->cookie_name),$this->cookie);
|
||||
}
|
||||
else $this->new_cookie();
|
||||
|
||||
$db->deconnexion();
|
||||
}
|
||||
else $this->new_cookie();
|
||||
}
|
||||
}
|
||||
|
||||
function put()
|
||||
{
|
||||
global $config;
|
||||
|
||||
if($config['session']=='1' && !empty($this->xid))
|
||||
{
|
||||
$db = new bdd();
|
||||
$db->connexion();
|
||||
|
||||
$time = time();
|
||||
|
||||
$var_session = serialize($this->values);
|
||||
|
||||
$db->escape($var_session);
|
||||
|
||||
$xid = $this->xid;
|
||||
|
||||
$table = $config['db_prefix']."sessions";
|
||||
$db->query("UPDATE $table SET time='$time', var_session='$var_session' WHERE xid='$xid'");
|
||||
$db->hash($table,"xid = '$xid'");
|
||||
|
||||
$db->deconnexion();
|
||||
}
|
||||
}
|
||||
|
||||
function close()
|
||||
{
|
||||
global $config;
|
||||
|
||||
if($config['session']=='1' && !empty($this->xid))
|
||||
{
|
||||
$db = new bdd();
|
||||
$db->connexion();
|
||||
|
||||
$xid = $this->xid;
|
||||
$table = $config['db_prefix']."sessions";
|
||||
$db->query("DELETE FROM $table WHERE xid = '$xid' AND active = '1'");
|
||||
|
||||
$db->deconnexion();
|
||||
|
||||
cookie((empty($this->cookie_name)?$config['session_name']:$this->cookie_name),$this->cookie,time()-3600);
|
||||
|
||||
$this->xid = NULL;
|
||||
$this->values = array();
|
||||
$this->level = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue