source: branches/feature-module-update/data/class/SC_Session.php @ 15079

Revision 15079, 3.3 KB checked in by nanasess, 17 years ago (diff)

svn:mime-type application/x-httpd-php; charset=UTF-8 設定

  • Property svn:mime-type set to application/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7
8/* セッション管理クラス */
9class SC_Session {
10    var $login_id;      // ログインユーザ名
11    var $authority;     // ユーザ権限
12    var $cert;          // 認証文字列(認証成功の判定に使用)
13    var $sid;           // セッションID
14    var $member_id;     // ログインユーザの主キー
15    var $uniqid;         // ページ遷移の正当性チェックに使用
16   
17    /* コンストラクタ */
18    function SC_Session() {
19        // セッション開始
20        sfDomainSessionStart();
21
22        // セッション情報の保存
23        if(isset($_SESSION['cert'])) {
24            $this->sid = session_id();
25            $this->cert = $_SESSION['cert'];
26            $this->login_id  = $_SESSION['login_id'];
27            $this->authority = $_SESSION['authority'];  // 管理者:0, 一般:1, 閲覧:2
28            $this->member_id = $_SESSION['member_id'];
29            $this->uniqid    = $_SESSION['uniq_id'];
30           
31            // ログに記録する
32            gfPrintLog("access : user=".$this->login_id." auth=".$this->authority." sid=".$this->sid);
33        } else {
34            // ログに記録する
35            gfPrintLog("access error.");
36        }
37    }
38    /* 認証成功の判定 */
39    function IsSuccess() {
40        global $arrPERMISSION;
41        if($this->cert == CERT_STRING) {
42            if(isset($arrPERMISSION[$_SERVER['PHP_SELF']])) {
43                // 数値が自分の権限以上のものでないとアクセスできない。
44                if($arrPERMISSION[$_SERVER['PHP_SELF']] < $this->authority) {           
45                    return AUTH_ERROR;
46                }
47            }
48            return SUCCESS;
49        }
50       
51        return ACCESS_ERROR;
52    }
53   
54    /* セッションの書き込み */
55    function SetSession($key, $val) {
56        $_SESSION[$key] = $val;
57    }
58   
59    /* セッションの読み込み */
60    function GetSession($key) {
61        return $_SESSION[$key];
62    }
63   
64    /* セッションIDの取得 */
65    function GetSID() {
66        return $this->sid;
67    }
68   
69    /** ユニークIDの取得 **/
70    function getUniqId() {
71        // ユニークIDがセットされていない場合はセットする。
72        if( empty($_SESSION['uniqid']) ) {
73            $this->setUniqId();
74        }
75        return $this->GetSession('uniqid');
76    }
77   
78    /** ユニークIDのセット **/
79    function setUniqId() {
80        // 予測されないようにランダム文字列を付与する。
81        $this->SetSession('uniqid', sfGetUniqRandomId());
82    }
83   
84    /* セッションの破棄 */
85    function EndSession() {
86        // デフォルトは、「PHPSESSID」
87        $sname = session_name();
88        // セッション変数を全て解除する
89        $_SESSION = array();
90        // セッションを切断するにはセッションクッキーも削除する。
91        // Note: セッション情報だけでなくセッションを破壊する。
92        if (isset($_COOKIE[$sname])) {
93            setcookie($sname, '', time()-42000, '/');
94        }
95        // 最終的に、セッションを破壊する
96        session_destroy();
97        // ログに記録する
98        gfPrintLog("logout : user=".$this->login_id." auth=".$this->authority." sid=".$this->sid);
99    }
100   
101    // 関連セッションのみ破棄する。
102    function logout() {
103        unset($_SESSION['cert']);
104        unset($_SESSION['login_id']);
105        unset($_SESSION['authority']);
106        unset($_SESSION['member_id']);
107        unset($_SESSION['uniqid']);
108        // ログに記録する
109        gfPrintLog("logout : user=".$this->login_id." auth=".$this->authority." sid=".$this->sid);
110    }
111}
112?>
Note: See TracBrowser for help on using the repository browser.