source: branches/version-2_5-dev/data/class/SC_Session.php @ 20764

Revision 20764, 4.7 KB checked in by nanasess, 13 years ago (diff)

#601 (コピーライトの更新)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24/* セッション管理クラス */
25class SC_Session {
26
27    /** ログインユーザ名 */
28    var $login_id;
29
30    /** ユーザ権限 */
31    var $authority;
32
33    /** 認証文字列(認証成功の判定に使用) */
34    var $cert;
35
36    /** セッションID */
37    var $sid;
38
39    /** ログインユーザの主キー */
40    var $member_id;
41
42    /** ページ遷移の正当性チェックに使用 */
43    var $uniqid;
44
45    /* コンストラクタ */
46    function SC_Session() {
47        // セッション情報の保存
48        if(isset($_SESSION['cert'])) {
49            $this->sid = session_id();
50            $this->cert = $_SESSION['cert'];
51            $this->login_id  = $_SESSION['login_id'];
52            // 管理者:0, 店舗オーナー:1, 閲覧:2, 販売担当:3 (XXX 現状 0, 1 を暫定実装。2, 3 は未実装。)
53            $this->authority = $_SESSION['authority'];
54            $this->member_id = $_SESSION['member_id'];
55            if (isset($_SESSION['uniq_id'])) {
56                $this->uniqid    = $_SESSION['uniq_id'];
57            }
58
59            // ログに記録する
60            GC_Utils_Ex::gfPrintLog("access : user=".$this->login_id." auth=".$this->authority." sid=".$this->sid);
61        } else {
62            // ログに記録する
63            GC_Utils_Ex::gfPrintLog("access error.");
64        }
65    }
66    /* 認証成功の判定 */
67    function IsSuccess() {
68        global $arrPERMISSION;
69        if($this->cert == CERT_STRING) {
70            if(isset($arrPERMISSION[$_SERVER['PHP_SELF']])) {
71                // 数値が自分の権限以上のものでないとアクセスできない。
72                if($arrPERMISSION[$_SERVER['PHP_SELF']] < $this->authority) {
73                    return AUTH_ERROR;
74                }
75            }
76            return SUCCESS;
77        }
78
79        return ACCESS_ERROR;
80    }
81
82    /* セッションの書き込み */
83    function SetSession($key, $val) {
84        $_SESSION[$key] = $val;
85    }
86
87    /* セッションの読み込み */
88    function GetSession($key) {
89        return $_SESSION[$key];
90    }
91
92    /* セッションIDの取得 */
93    function GetSID() {
94        return $this->sid;
95    }
96
97    /** ユニークIDの取得 **/
98    function getUniqId() {
99        // ユニークIDがセットされていない場合はセットする。
100        if( empty($_SESSION['uniqid']) ) {
101            $this->setUniqId();
102        }
103        return $this->GetSession('uniqid');
104    }
105
106    /** ユニークIDのセット **/
107    function setUniqId() {
108        // 予測されないようにランダム文字列を付与する。
109        $this->SetSession('uniqid', SC_Utils_Ex::sfGetUniqRandomId());
110    }
111
112    /* セッションの破棄 */
113    function EndSession() {
114        // デフォルトは、「PHPSESSID」
115        $sname = session_name();
116        // セッション変数を全て解除する
117        $_SESSION = array();
118        // セッションを切断するにはセッションクッキーも削除する。
119        // Note: セッション情報だけでなくセッションを破壊する。
120        if (isset($_COOKIE[$sname])) {
121            setcookie($sname, '', time()-42000, '/');
122        }
123        // 最終的に、セッションを破壊する
124        session_destroy();
125        // ログに記録する
126        GC_Utils_Ex::gfPrintLog("logout : user=".$this->login_id." auth=".$this->authority." sid=".$this->sid);
127    }
128
129    // 関連セッションのみ破棄する。
130    function logout() {
131        unset($_SESSION['cert']);
132        unset($_SESSION['login_id']);
133        unset($_SESSION['authority']);
134        unset($_SESSION['member_id']);
135        unset($_SESSION['uniqid']);
136        // トランザクショントークンを破棄
137        SC_Helper_Session_Ex::destroyToken();
138        // ログに記録する
139        GC_Utils_Ex::gfPrintLog("logout : user=".$this->login_id." auth=".$this->authority." sid=".$this->sid);
140    }
141}
142?>
Note: See TracBrowser for help on using the repository browser.