PHP код:
<?php
// $Id: sessions.class.php,v 1.2 2005/06/08 08:32:52 FARSUS Exp $
//***********************************************************/
//* RUNCMS */
//* Simplicity & ease off use */
//* < http://www.runcms.org > */
//***********************************************************/
// Original Author: Kazumi Ono
// Author Website : http://www.mywebaddons.com/ , http://www.myweb.ne.jp
// License Type : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------- //
if (!defined("EXOOPS_SESSION_CLASS_INCLUDED")) {
define("EXOOPS_SESSION_CLASS_INCLUDED", 1);
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
class XoopsUserSession {
var $db;
var $uid;
var $uname;
var $hash;
var $pass;
var $cookie;
var $expiretime;
var $sessionID;
function XoopsUserSession($sessionID ='')
{
global $xoopsConfig, $myts;
$this->cookie = $xoopsConfig['session_name'];
$this->expiretime = $xoopsConfig['session_expire'];
if(!empty($sessionID)){
$this->sessionID = $myts->oopsAddSlashesGPC(trim($sessionID));
}
}
//---------------------------------------------------------------------------------------//
/**
* creates new session for user
* and sets a cookie containing the session id
*
* @param type $var description
* @return type description
*/
function store() {
global $db, $_SESSION, $xoopsConfig;
$db->query("DELETE FROM ".$db->prefix("session")." WHERE uid=".$this->uid);
$this->hash = md5($this->uid.':'.$this->pass.':'._HTTP_USER_AGENT);
if ($db->query("INSERT INTO ".$db->prefix("session")." SET uid=".$this->uid.", uname='".$this->uname."', time=".time().", hash='".$this->hash."'")) {
if ($xoopsConfig['use_sessions'] == 1) {
session_register($xoopsConfig['session_name']);
$_SESSION[$xoopsConfig['session_name']] = $this->hash;
} else {
cookie($this->cookie, $this->hash, $this->expiretime);
}
return true;
}
return false;
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function setUid($value) {
$this->uid = $value;
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function setUname($value) {
$this->uname = $value;
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function setPass($value) {
$this->pass = $value;
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function uid() {
return $this->uid;
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function isValid() {
global $db;
$mintime = (time()-$this->expiretime);
$db->query("DELETE FROM ".$db->prefix("session")." WHERE time<$mintime");
$sql = "
SELECT
u.uid,
u.uname,
u.pass,
s.hash
FROM ".$db->prefix("session")." s
INNER JOIN ".$db->prefix("users")." u ON u.uid=s.uid
WHERE s.hash='".$this->sessionID."'";
if ( !$result = $db->query($sql) ) {
return false;
}
list($uid, $uname, $pass, $hash) = $db->fetch_row($result);
if ( !empty($uid) ) {
if ($this->sessionID == md5($uid.':'.$pass.':'._HTTP_USER_AGENT)) {
$this->uid = $uid;
$this->uname = $uname;
$this->pass = $pass;
$this->hash = $hash;
return true;
}
}
return false;
}
//---------------------------------------------------------------------------------------//
/**
* updates the session table
*
* @param type $var description
* @return type description
*/
function update() {
global $db, $_SESSION, $xoopsConfig;
$db->query("UPDATE ".$db->prefix("session")." SET time=".time()." WHERE uid=".$this->uid);
if ($xoopsConfig['use_sessions'] == 1) {
$_SESSION[$xoopsConfig['session_name']] = $this->hash;
} else {
cookie($this->cookie, $this->hash, $this->expiretime);
}
}
//---------------------------------------------------------------------------------------//
} // END XOOPSUSERSESSION
// ------------------------------------------------------------------------- //
}
?>