public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
cmsmadesimple-2-0 / lib / classes / class.cms_session.php
100644 87 lines (79 sloc) 2.344 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php // -*- mode:php; tab-width:4; indent-tabs-mode:t; c-basic-offset:4; -*-
#CMS - CMS Made Simple
#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
#This project's homepage is: http://cmsmadesimple.org
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id$
 
/**
* Static methods for handling session creation.
*
* @author Ted Kulp
* @since 2.0
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license GPL
**/
class CmsSession extends CmsObject
{
  function __construct()
  {
    parent::__construct();
  }
  
  /**
   * Sets up the session properly for the system
   *
   * @return void
   * @author Ted Kulp
   **/
  public static function setup()
  {
    #Setup session with different id and start it
    @session_name('CMSSESSID' . CmsSession::generate_session_key());
    @ini_set('url_rewriter.tags', '');
    @ini_set('session.use_trans_sid', 0);
    
    if(!@session_id())
    {
     @session_start();
    }
    #Add users if they exist in the session
    $gCms = cmsms();
 
    $gCms->variables['user_id'] = '';
    if (isset($_SESSION['cmsms_user_id']))
    {
     $gCms->variables['user_id'] = $_SESSION['cmsms_user_id'];
    }
 
    $gCms->variables['username'] = '';
    if (isset($_SESSION['cms_admin_username']))
    {
     $gCms->variables['username'] = $_SESSION['cms_admin_username'];
    }
  }
  
  /**
   * Generates a string that should be unique value depending on the directory
   * that CMSMS resides in. Allows us to have multiple CMSMS installs on the
   * same domain and not share sessions.
   *
   * @return string
   * @author Ted Kulp
   **/
  public static function generate_session_key()
  {
    return substr(md5(dirname(dirname(dirname(__FILE__)))), 0, 8);
  }
}
 
# vim:ts=4 sw=4 noet
?>