Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/database/table/session.php

Documentation is available at session.php

  1. <?php
  2. /**
  3. @version        $Id: session.php 6543 2007-02-09 14:03:09Z pasamio $
  4. @package        Joomla.Framework
  5. @subpackage    Table
  6. @copyright    Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
  7. @license        GNU/GPL, see LICENSE.php
  8. *  Joomla! is free software. This version may have been modified pursuant
  9. *  to the GNU General Public License, and as distributed it includes or
  10. *  is derivative of works licensed under the GNU General Public License or
  11. *  other free or open source software licenses.
  12. *  See COPYRIGHT.php for copyright notices and details.
  13. */
  14.  
  15. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE'or die();
  17.  
  18. /**
  19.  * Session table
  20.  *
  21.  * @package     Joomla.Framework
  22.  * @subpackage        Table
  23.  * @since    1.0
  24.  */
  25. class JTableSession extends JTable
  26. {
  27.     /**
  28.      *
  29.      * @var int Primary key
  30.      */
  31.     var $session_id            = null;
  32.  
  33.     /**
  34.      *
  35.      * @var string 
  36.      */
  37.     var $time                = null;
  38.  
  39.     /**
  40.      *
  41.      * @var string 
  42.      */
  43.     var $userid                = null;
  44.  
  45.     /**
  46.      *
  47.      * @var string 
  48.      */
  49.     var $usertype            = null;
  50.  
  51.     /**
  52.      *
  53.      * @var string 
  54.      */
  55.     var $username            = null;
  56.  
  57.     /**
  58.      *
  59.      * @var time 
  60.      */
  61.     var $gid                = null;
  62.  
  63.     /**
  64.      *
  65.      * @var int 
  66.      */
  67.     var $guest                = null;
  68.  
  69.     /**
  70.      *
  71.      * @var int 
  72.      */
  73.     var $client_id            = null;
  74.  
  75.     /**
  76.      *
  77.      * @var string 
  78.      */
  79.     var $data                = null;
  80.  
  81.     /**
  82.      * Constructor
  83.      * @param database A database connector object
  84.      */
  85.     function __construct&$db )
  86.     {
  87.         parent::__construct'#__session''session_id'$db );
  88.  
  89.         $this->guest     = 1;
  90.         $this->username = '';
  91.         $this->gid         = 0;
  92.     }
  93.  
  94.     function insert($sessionId$clientId)
  95.     {
  96.         $this->session_id    = $sessionId;
  97.         $this->client_id    = $clientId;
  98.  
  99.         $this->time = time();
  100.         $ret $this->_db->insertObject$this->_tbl$this'session_id' );
  101.  
  102.         if!$ret {
  103.             $this->_error = strtolower(get_class$this ))."::"JText::_'store failed' ."<br />" $this->_db->stderr();
  104.             return false;
  105.         else {
  106.             return true;
  107.         }
  108.     }
  109.  
  110.     function update$updateNulls false )
  111.     {
  112.         $this->time = time();
  113.         $ret $this->_db->updateObject$this->_tbl$this'session_id'$updateNulls );
  114.  
  115.         if!$ret {
  116.             $this->_error = strtolower(get_class$this ))."::"JText::_'store failed' ." <br />" $this->_db->stderr();
  117.             return false;
  118.         else {
  119.             return true;
  120.         }
  121.     }
  122.  
  123.     /**
  124.      * Destroys the pesisting session
  125.      */
  126.     function destroy($sessionId)
  127.     {
  128.         $query 'DELETE FROM #__session'
  129.             . ' WHERE session_id = '$this->_db->Quote$sessionId );
  130.         $this->_db->setQuery$query );
  131.  
  132.         if !$this->_db->query() ) {
  133.             $this->_error =  $this->_db->stderr();
  134.             return false;
  135.         }
  136.  
  137.         return true;
  138.     }
  139.  
  140.     /**
  141.     * Purge old sessions
  142.     *
  143.     * @param int     Session age in seconds
  144.     * @return mixed Resource on success, null on fail
  145.     */
  146.     function purge$maxLifetime 1440 )
  147.     {
  148.         $past time($maxLifetime;
  149.         $query 'DELETE FROM '$this->_tbl .' WHERE ( time < '$past .' )';
  150.         ;
  151.         $this->_db->setQuery($query);
  152.  
  153.         return $this->_db->query();
  154.     }
  155.  
  156.     /**
  157.      * Find out if a user has a one or more active sessions
  158.      *
  159.      * @param int $userid The identifier of the user
  160.      * @return boolean True if a session for this user exists
  161.      */
  162.     function exists($userid)
  163.     {
  164.         $query 'SELECT COUNT(userid) FROM #__session'
  165.             . ' WHERE userid = '$this->_db->Quote$userid );
  166.         $this->_db->setQuery$query );
  167.  
  168.         if !$result $this->_db->loadResult() ) {
  169.             $this->_error =  $this->_db->stderr();
  170.             return false;
  171.         }
  172.  
  173.         return (boolean) $result;
  174.     }
  175. }
  176. ?>

Documentation generated on Mon, 05 Mar 2007 21:21:20 +0000 by phpDocumentor 1.3.1