123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- if(function_exists('ini_set'))
- {
- @ini_set('session.use_cookies','1');
- @ini_set('session.use_only_cookies','1');
- @ini_set('url_rewriter.tags','');
- @ini_set('session.use_trans_sid','0');
- }
- $con = new connection(DB_USER,DB_PASS,DB_HOST,DB_DBASE);
- $dc_session = new dbSession($con,DB_PREFIX.'session');
- session_set_save_handler(
- array(&$dc_session, '_open'),
- array(&$dc_session, '_close'),
- array(&$dc_session, '_read'),
- array(&$dc_session, '_write'),
- array(&$dc_session, '_destroy'),
- array(&$dc_session, '_gc')
- );
- session_name(DC_SESSION_NAME);
- session_start();
- class dbSession
- {
- var $con;
- var $table;
- var $sess_ttl = '-120 minutes';
-
- function dbSession(&$con,$table)
- {
- $this->con = $con;
- $this->table = $table;
- }
-
- function _open($path,$name)
- {
- return true;
- }
-
- function _close()
- {
- $this->_gc();
- return true;
- }
-
- function _read($ses_id)
- {
- $strReq = 'SELECT * FROM '.$this->table.' '.
- 'WHERE ses_id = \''.$ses_id.'\' ';
-
- $rs = $this->con->select($strReq);
-
- if ($rs->isEmpty()) {
- return '';
- } else {
- return $rs->f('ses_value');
- }
- }
-
- function _write($ses_id, $data)
- {
- $strReq = 'UPDATE '.$this->table.' SET '.
- 'ses_time = \''.time().'\', '.
- 'ses_value = \''.$data.'\' '.
- 'WHERE ses_id = \''.$ses_id.'\' ';
-
- if ($this->con->execute($strReq) === false) {
- return false;
- }
-
- if ($this->con->rowCount() > 0) {
- return true;
- }
-
- $strReq = 'INSERT INTO '.$this->table.' '.
- ' (ses_id, ses_time, ses_start, ses_value) VALUES ('.
- '\''.$ses_id.'\','.
- '\''.time().'\','.
- '\''.time().'\','.
- '\''.$data.'\') ';
-
- if ($this->con->execute($strReq) === false) {
- return false;
- }
-
- return true;
- }
-
- function _destroy($ses_id)
- {
- $strReq = 'DELETE FROM '.$this->table.' '.
- 'WHERE ses_id = \''.$ses_id.'\' ';
-
- if ($this->con->execute($strReq) === false) {
- return false;
- } else {
- $this->_optimize();
- return true;
- }
- }
-
- function _gc()
- {
- $ses_life = strtotime($this->sess_ttl);
-
- $strReq = 'DELETE FROM '.$this->table.' '.
- 'WHERE ses_time < '.$ses_life.' ';
-
- if ($this->con->execute($strReq) === false) {
- return false;
- }
-
- if ($this->con->rowCount() > 0) {
- $this->_optimize();
- }
-
- return true;
- }
-
- function _optimize()
- {
- $strReq = 'OPTIMIZE TABLE '.$this->table.' ';
-
- if ($this->con->execute($strReq) === false) {
- return false;
- } else {
- return true;
- }
- }
- }
- ?>
|