Exemplo n.º 1
0
    public static function getSessionById($sessionId = null, $session = null)
    {
        $configs = Gio_Core_Config_Xml::getConfig('session');
        $sessionId = $sessionId ? $sessionId : self::getId();
        $mysql = new Gio_Db_Mysql();
        /**
         * Clear Session Expried
         */
        $sql = 'DELETE FROM ' . $mysql->_tablePrefix . 'core_session
					WHERE last_update + lifetime < ' . strtotime(date('Y-m-d H:i:s'));
        $rs = $mysql->query($sql);
        $mysql->freeResult($rs);
        /**
         * Update Session Status
         */
        $sql = 'UPDATE ' . $mysql->_tablePrefix . 'core_session
				SET status = "inactive"
				WHERE last_update + inactive_time < ' . strtotime(date('Y-m-d H:i:s'));
        $rs = $mysql->query($sql);
        $mysql->freeResult($rs);
        /**
         * 
         */
        $sql = 'SELECT * FROM ' . $mysql->_tablePrefix . 'core_session 
						WHERE session_id = "' . $mysql->escape($sessionId) . '" LIMIT 1';
        $rs = $mysql->query($sql);
        $row = 0 == $mysql->count($rs) ? null : $mysql->fetchAll($rs);
        $json = new Services_JSON();
        if (null == $row) {
            $request = Gio_Core_Request::getInstance();
            $session = array('session_id' => $sessionId, 'data' => null, 'created_date' => time(), 'last_update' => time(), 'lifetime' => isset($configs->lifetime) ? $configs->lifetime : 3600, 'inactive_time' => isset($configs->inactive) ? $configs->inactive : 120, 'ip' => $request->getRemoteIp());
            $mysql->insert($session, $mysql->_tablePrefix . 'core_session');
            return $session;
        }
        self::lastUpdate(time(), $row['session_id']);
        if ($session != null) {
            self::update($session['data'], $session['session_id']);
            return $session;
        }
        return $row;
    }