コード例 #1
0
ファイル: adodb-session.php プロジェクト: amjadtbssm/website
 function write($key, $val)
 {
     global $ADODB_SESSION_READONLY;
     if (!empty($ADODB_SESSION_READONLY)) {
         return;
     }
     $clob = ADODB_Session::clob();
     $conn =& ADODB_Session::_conn();
     $crc = ADODB_Session::_crc();
     $data = ADODB_Session::dataFieldName();
     $debug = ADODB_Session::debug();
     $driver = ADODB_Session::driver();
     $expire_notify = ADODB_Session::expireNotify();
     $filter = ADODB_Session::filter();
     $lifetime = ADODB_Session::lifetime();
     $table = ADODB_Session::table();
     if (!$conn) {
         return false;
     }
     $qkey = $conn->qstr($key);
     //assert('$table');
     $expiry = time() + $lifetime;
     $binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : '';
     // crc32 optimization since adodb 2.1
     // now we only update expiry date, thx to sebastian thom in adodb 2.32
     if ($crc !== false && $crc == strlen($val) . crc32($val)) {
         if ($debug) {
             ADOConnection::outp('<p>Session: Only updating date - crc32 not changed</p>');
         }
         $expirevar = '';
         if ($expire_notify) {
             $var = reset($expire_notify);
             global ${$var};
             if (isset(${$var})) {
                 $expirevar = ${$var};
             }
         }
         $sql = "UPDATE {$table} SET expiry = " . $conn->Param('0') . ",expireref=" . $conn->Param('1') . " WHERE {$binary} sesskey = " . $conn->Param('2') . " AND expiry >= " . $conn->Param('3');
         $rs =& $conn->Execute($sql, array($expiry, $expirevar, $key, time()));
         return true;
     }
     $val = rawurlencode($val);
     foreach ($filter as $f) {
         if (is_object($f)) {
             $val = $f->write($val, ADODB_Session::_sessionKey());
         }
     }
     $arr = array('sesskey' => $key, 'expiry' => $expiry, $data => $val, 'expireref' => '');
     if ($expire_notify) {
         $var = reset($expire_notify);
         global ${$var};
         if (isset(${$var})) {
             $arr['expireref'] = ${$var};
         }
     }
     if (!$clob) {
         // no lobs, simply use replace()
         $arr[$data] = $conn->qstr($val);
         $rs = $conn->Replace($table, $arr, 'sesskey', $autoQuote = true);
     } else {
         // what value shall we insert/update for lob row?
         switch ($driver) {
             // empty_clob or empty_lob for oracle dbs
             case 'oracle':
             case 'oci8':
             case 'oci8po':
             case 'oci805':
                 $lob_value = sprintf('empty_%s()', strtolower($clob));
                 break;
                 // null for all other
             // null for all other
             default:
                 $lob_value = 'null';
                 break;
         }
         $conn->StartTrans();
         $expiryref = $conn->qstr($arr['expireref']);
         // do we insert or update? => as for sesskey
         $rs =& $conn->Execute("SELECT COUNT(*) AS cnt FROM {$table} WHERE {$binary} sesskey = {$qkey}");
         if ($rs && reset($rs->fields) > 0) {
             $sql = "UPDATE {$table} SET expiry = {$expiry}, {$data} = {$lob_value}, expireref={$expiryref} WHERE  sesskey = {$qkey}";
         } else {
             $sql = "INSERT INTO {$table} (expiry, {$data}, sesskey,expireref) VALUES ({$expiry}, {$lob_value}, {$qkey},{$expiryref})";
         }
         if ($rs) {
             $rs->Close();
         }
         $err = '';
         $rs1 =& $conn->Execute($sql);
         if (!$rs1) {
             $err = $conn->ErrorMsg() . "\n";
         }
         $rs2 =& $conn->UpdateBlob($table, $data, $val, " sesskey={$qkey}", strtoupper($clob));
         if (!$rs2) {
             $err .= $conn->ErrorMsg() . "\n";
         }
         $rs = $rs && $rs2 ? true : false;
         $conn->CompleteTrans();
     }
     if (!$rs) {
         ADOConnection::outp('<p>Session Replace: ' . $conn->ErrorMsg() . '</p>', false);
         return false;
     } else {
         // bug in access driver (could be odbc?) means that info is not committed
         // properly unless select statement executed in Win2000
         if ($conn->databaseType == 'access') {
             $sql = "SELECT sesskey FROM {$table} WHERE {$binary} sesskey = {$qkey}";
             $rs =& $conn->Execute($sql);
             ADODB_Session::_dumprs($rs);
             if ($rs) {
                 $rs->Close();
             }
         }
     }
     /*
     		if (ADODB_Session::Lock()) {
     			$conn->CommitTrans();
     		}*/
     return $rs ? true : false;
 }
コード例 #2
0
<?php

/*
V5.04 13 Feb 2008   (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
         Contributed by Ross Smith (adodb@netebb.com). 
  Released under both BSD license and Lesser GPL library license.
  Whenever there is any discrepancy between the two licenses,
  the BSD license will take precedence.
	  Set tabs to 4 for best viewing.
*/
/*
This file is provided for backwards compatibility purposes
*/
if (!defined('ADODB_SESSION')) {
    require_once dirname(__FILE__) . '/adodb-session.php';
}
require_once ADODB_SESSION . '/adodb-encrypt-md5.php';
ADODB_Session::filter(new ADODB_Encrypt_MD5());
コード例 #3
0
ファイル: adodb-session2.php プロジェクト: fgbreel/ADOdb
 static function write($key, $oval)
 {
     global $ADODB_SESSION_READONLY;
     if (!empty($ADODB_SESSION_READONLY)) {
         return;
     }
     $clob = ADODB_Session::clob();
     $conn = ADODB_Session::_conn();
     $crc = ADODB_Session::_crc();
     $debug = ADODB_Session::debug();
     $driver = ADODB_Session::driver();
     $expire_notify = ADODB_Session::expireNotify();
     $filter = ADODB_Session::filter();
     $lifetime = ADODB_Session::lifetime();
     $table = ADODB_Session::table();
     if (!$conn) {
         return false;
     }
     if ($debug) {
         $conn->debug = 1;
     }
     $sysTimeStamp = $conn->sysTimeStamp;
     //assert('$table');
     $expiry = $conn->OffsetDate($lifetime / (24 * 3600), $sysTimeStamp);
     $binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : '';
     // crc32 optimization since adodb 2.1
     // now we only update expiry date, thx to sebastian thom in adodb 2.32
     if ($crc !== '00' && $crc !== false && $crc == strlen($oval) . crc32($oval)) {
         if ($debug) {
             echo '<p>Session: Only updating date - crc32 not changed</p>';
         }
         $expirevar = '';
         if ($expire_notify) {
             $var = reset($expire_notify);
             global ${$var};
             if (isset(${$var})) {
                 $expirevar = ${$var};
             }
         }
         $sql = "UPDATE {$table} SET expiry = {$expiry} ,expireref=" . $conn->Param('0') . ", modified = {$sysTimeStamp} WHERE {$binary} sesskey = " . $conn->Param('1') . " AND expiry >= {$sysTimeStamp}";
         $rs = $conn->Execute($sql, array($expirevar, $key));
         return true;
     }
     $val = rawurlencode($oval);
     foreach ($filter as $f) {
         if (is_object($f)) {
             $val = $f->write($val, ADODB_Session::_sessionKey());
         }
     }
     $expireref = '';
     if ($expire_notify) {
         $var = reset($expire_notify);
         global ${$var};
         if (isset(${$var})) {
             $expireref = ${$var};
         }
     }
     if (!$clob) {
         // no lobs, simply use replace()
         $rs = $conn->Execute("SELECT COUNT(*) AS cnt FROM {$table} WHERE {$binary} sesskey = " . $conn->Param(0), array($key));
         if ($rs) {
             $rs->Close();
         }
         if ($rs && reset($rs->fields) > 0) {
             $sql = "UPDATE {$table} SET expiry={$expiry}, sessdata=" . $conn->Param(0) . ", expireref= " . $conn->Param(1) . ",modified={$sysTimeStamp} WHERE sesskey = " . $conn->Param(2);
         } else {
             $sql = "INSERT INTO {$table} (expiry, sessdata, expireref, sesskey, created, modified)\n\t\t\t\t\tVALUES ({$expiry}," . $conn->Param('0') . ", " . $conn->Param('1') . ", " . $conn->Param('2') . ", {$sysTimeStamp}, {$sysTimeStamp})";
         }
         $rs = $conn->Execute($sql, array($val, $expireref, $key));
     } else {
         // what value shall we insert/update for lob row?
         if (strncmp($driver, 'oci8', 4) == 0) {
             $lob_value = sprintf('empty_%s()', strtolower($clob));
         } else {
             $lob_value = 'null';
         }
         $conn->StartTrans();
         $rs = $conn->Execute("SELECT COUNT(*) AS cnt FROM {$table} WHERE {$binary} sesskey = " . $conn->Param(0), array($key));
         if ($rs && reset($rs->fields) > 0) {
             $sql = "UPDATE {$table} SET expiry={$expiry}, sessdata={$lob_value}, expireref= " . $conn->Param(0) . ",modified={$sysTimeStamp} WHERE sesskey = " . $conn->Param('1');
         } else {
             $sql = "INSERT INTO {$table} (expiry, sessdata, expireref, sesskey, created, modified)\n\t\t\t\t\tVALUES ({$expiry},{$lob_value}, " . $conn->Param('0') . ", " . $conn->Param('1') . ", {$sysTimeStamp}, {$sysTimeStamp})";
         }
         $rs = $conn->Execute($sql, array($expireref, $key));
         $qkey = $conn->qstr($key);
         $rs2 = $conn->UpdateBlob($table, 'sessdata', $val, " sesskey={$qkey}", strtoupper($clob));
         if ($debug) {
             echo "<hr>", htmlspecialchars($oval), "<hr>";
         }
         $rs = @$conn->CompleteTrans();
     }
     if (!$rs) {
         ADOConnection::outp('<p>Session Replace: ' . $conn->ErrorMsg() . '</p>', false);
         return false;
     } else {
         // bug in access driver (could be odbc?) means that info is not committed
         // properly unless select statement executed in Win2000
         if ($conn->databaseType == 'access') {
             $sql = "SELECT sesskey FROM {$table} WHERE {$binary} sesskey = {$qkey}";
             $rs = $conn->Execute($sql);
             ADODB_Session::_dumprs($rs);
             if ($rs) {
                 $rs->Close();
             }
         }
     }
     /*
     		if (ADODB_Session::Lock()) {
     			$conn->CommitTrans();
     		}*/
     return $rs ? true : false;
 }
コード例 #4
0
ファイル: adodb-session.php プロジェクト: briandodson/bdcms
 function sess_write($sess_id, $data)
 {
     $filter = ADODB_Session::filter();
     $dataFieldName = ADODB_Session::dataFieldName();
     $db_object =& $GLOBALS['ADODB_SESS_CONN'];
     $table = $GLOBALS['ADODB_SESSION_TBL'];
     if (isset($GLOBALS['ADODB_SESS_LIFE'])) {
         $lifetime = $GLOBALS['ADODB_SESS_LIFE'];
     } else {
         $lifetime = ini_get('session.gc_maxlifetime');
         if ($lifetime <= 1) {
             $lifetime = 1440;
         }
     }
     $expire_notify = $GLOBALS['ADODB_SESSION_EXPIRE_NOTIFY'];
     $notify = '';
     if (isset($expire_notify)) {
         $var = reset($expire_notify);
         global ${$var};
         if (isset(${$var})) {
             $notify = ${$var};
         }
     }
     $CurrentTime = time() + $lifetime;
     $data = rawurlencode($data);
     foreach ($filter as $f) {
         if (is_object($f)) {
             $data = $f->write($data, ADODB_Session::_sessionKey());
         }
     }
     $db_object->execute("UPDATE {$table} SET {$dataFieldName} = '{$data}', expiry = '{$CurrentTime}', expireref = '{$notify}' WHERE SessionID = '{$sess_id}'");
     return true;
 }
コード例 #5
0
 require_once '../session/adodb-session.php';
 $encryption = array('', 'adodb-encrypt-mcrypt.php', 'adodb-encrypt-md5.php', 'adodb-encrypt-ordcrypt.php', 'adodb-encrypt-secret.php', 'adodb-encrypt-sha1.php');
 $encryption_object = array('', 'ADODB_Encrypt_MCrypt', 'ADODB_Encrypt_MD5', 'ADODB_Encrypt_OrdCrypt', 'ADODB_Encrypt_Secret', 'ADODB_Encrypt_SHA1');
 $encryption_name = array('None', 'MCrypt', 'MD5', 'OrdCrypt', 'Secret', 'SHA1');
 $compression = array('', 'adodb-compress-bzip2.php', 'adodb-compress-gzip.php');
 $compression_object = array('', 'ADODB_Compress_Bzip2', 'ADODB_Compress_Gzip');
 $compression_name = array('None', 'Bzip2', 'Gzip');
 if ($_POST['encrypt'] > 0) {
     require_once ADODB_SESSION . '/' . $encryption[$_POST['encrypt']];
     $object = $encryption_object[$_POST['encrypt']];
     ADODB_Session::filter(new $object());
 }
 if ($_POST['compress'] > 0) {
     require_once ADODB_SESSION . '/' . $compression[$_POST['compress']];
     $object = $compression_object[$_POST['compress']];
     ADODB_Session::filter(new $object());
 }
 $db = ADONewConnection($_POST['databasetype']);
 $db->createdatabase = true;
 $result = $db->Connect($_POST['dbhost'], $_POST['dbusername'], $_POST['dbpassword'], $_POST['databasename']);
 if (!$result) {
     die("Could not connect to the database.");
 }
 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
 function ExpiredSession($expireref, $sesskey)
 {
     echo "Session USERID: {$expireref} - expired<br>";
     echo "Session Key: {$sesskey}<br><br>";
 }
 if ($_POST['databasetype'] == 'mysql' || $_POST['databasetype'] == 'mysqli' || $_POST['databasetype'] == 'mysqlt') {
     $res = $db->Execute("DROP TABLE IF EXISTS `sessions`");
コード例 #6
0
ファイル: adodb-session-demo.php プロジェクト: Artea/freebeer
$ADODB_SESSION_TBL = $table;
$ADODB_SESSION_USER = $user;
$ADODB_SESSION_USE_LOBS = $clob;
$ADODB_SESS_DEBUG = $debug;
$ADODB_SESS_LIFE = $lifetime;
if ($optimize) {
    define('ADODB_SESSION_OPTIMIZE', $optimize);
}
define('ADODB_SESSION_SYNCH_SECS', $sync_seconds);
if (class_exists('ADODB_Session')) {
    ADODB_Session::clob($clob);
    ADODB_Session::dataFieldName($data_field_name);
    ADODB_Session::database($database);
    ADODB_Session::debug($debug);
    ADODB_Session::driver($driver);
    ADODB_Session::filter($filters);
    ADODB_Session::host($host);
    ADODB_Session::lifetime($lifetime);
    ADODB_Session::optimize($optimize);
    ADODB_Session::password($password);
    ADODB_Session::syncSeconds($sync_seconds);
    ADODB_Session::table($table);
    ADODB_Session::user($user);
}
function NotifyFn($var, $sesskey)
{
    echo "NotifyFn({$var}, {$sesskey}) called<br />\n";
}
if ($expire_notify) {
    $ADODB_SESSION_EXPIRE_NOTIFY = array('debug', 'NotifyFn');
    if (class_exists('ADODB_Session')) {
コード例 #7
0
        // Since we now have the config values(including perf_logging), if the admin wants perf logging on - turn it on.
        if (isset($perf_logging) && $perf_logging) {
            $debug_query = $db->SelectLimit("SELECT * from {$db_prefix}adodb_logsql", 1);
            if ($debug_query) {
                adodb_perf::table("{$db_prefix}adodb_logsql");
                $db->LogSQL();
            }
        }
    }
    // Ensure that the sessions table has been created, and if so, start a session.
    // I bet there is a more elegant way to do this, but this works for all my testing scenarios, so its in for now.
    $debug_query = $db->Execute("SHOW TABLES LIKE '{$db_prefix}sessions'");
    db_op_result($debug_query, __LINE__, __FILE__);
    $row = $debug_query->fields;
    if ($debug_query) {
        // We explicitly use encrypted sessions, but this adds compression as well.
        $ADODB_SESSION_TBL = $db_prefix . "sessions";
        ADODB_Session::filter(new ADODB_Compress_Gzip());
        // The data field name "data" violates SQL reserved words - switch it to session_data.
        ADODB_Session::dataFieldName('session_data');
        session_start();
    }
}
$smarty = new Smarty();
if (getenv("HTTP_X_FORWARDED_FOR")) {
    $ip = getenv("HTTP_X_FORWARDED_FOR");
    // Get Proxy IP address for user
} else {
    $ip = getenv("REMOTE_ADDR");
    // Get IP address for user
}