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

Revision 15289, 3.8 KB checked in by nanasess, 17 years ago (diff)

クラス化対応

  • Property svn:keywords set to Id
  • 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        SC_Utils_Ex::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            if (isset($_SESSION['uniq_id'])) {
30                $this->uniqid    = $_SESSION['uniq_id'];
31            }
32
33            // ログに記録する
34            GC_Utils_Ex::gfPrintLog("access : user=".$this->login_id." auth=".$this->authority." sid=".$this->sid);
35        } else {
36            // ログに記録する
37            GC_Utils_Ex::gfPrintLog("access error.");
38        }
39    }
40    /* 認証成功の判定 */
41    function IsSuccess() {
42        global $arrPERMISSION;
43        if($this->cert == CERT_STRING) {
44            if(isset($arrPERMISSION[$_SERVER['PHP_SELF']])) {
45                // 数値が自分の権限以上のものでないとアクセスできない。
46                if($arrPERMISSION[$_SERVER['PHP_SELF']] < $this->authority) {
47                    return AUTH_ERROR;
48                }
49            }
50            return SUCCESS;
51        }
52
53        return ACCESS_ERROR;
54    }
55
56    /* セッションの書き込み */
57    function SetSession($key, $val) {
58        $_SESSION[$key] = $val;
59    }
60
61    /* セッションの読み込み */
62    function GetSession($key) {
63        return $_SESSION[$key];
64    }
65
66    /* セッションIDの取得 */
67    function GetSID() {
68        return $this->sid;
69    }
70
71    /** ユニークIDの取得 **/
72    function getUniqId() {
73        // ユニークIDがセットされていない場合はセットする。
74        if( empty($_SESSION['uniqid']) ) {
75            $this->setUniqId();
76        }
77        return $this->GetSession('uniqid');
78    }
79
80    /** ユニークIDのセット **/
81    function setUniqId() {
82        // 予測されないようにランダム文字列を付与する。
83        $this->SetSession('uniqid', SC_Utils_Ex::sfGetUniqRandomId());
84    }
85
86    /* セッションの破棄 */
87    function EndSession() {
88        // デフォルトは、「PHPSESSID」
89        $sname = session_name();
90        // セッション変数を全て解除する
91        $_SESSION = array();
92        // セッションを切断するにはセッションクッキーも削除する。
93        // Note: セッション情報だけでなくセッションを破壊する。
94        if (isset($_COOKIE[$sname])) {
95            setcookie($sname, '', time()-42000, '/');
96        }
97        // 最終的に、セッションを破壊する
98        session_destroy();
99        // ログに記録する
100        GC_Utils_Ex::gfPrintLog("logout : user=".$this->login_id." auth=".$this->authority." sid=".$this->sid);
101    }
102
103    // 関連セッションのみ破棄する。
104    function logout() {
105        unset($_SESSION['cert']);
106        unset($_SESSION['login_id']);
107        unset($_SESSION['authority']);
108        unset($_SESSION['member_id']);
109        unset($_SESSION['uniqid']);
110        // ログに記録する
111        GC_Utils_Ex::gfPrintLog("logout : user=".$this->login_id." auth=".$this->authority." sid=".$this->sid);
112    }
113}
114?>
Note: See TracBrowser for help on using the repository browser.