source: branches/version-2_11-dev/data/class/SC_Session.php @ 20926

Revision 20926, 4.9 KB checked in by yomoro, 13 years ago (diff)

#1303 r20923では、URLにスラッシュを二重に記載すると、アクセスできてしまうので、2重のものは必ず一つ削除するように修正。

  • 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            $admin_path = preg_replace('/\/+/', '/', $_SERVER['PHP_SELF']);
71            $masterData                 = new SC_DB_MasterData_Ex();
72            $this->arrPERMISSION        = $masterData->getMasterData("mtb_permission");
73            if(isset($this->arrPERMISSION[$admin_path])) {
74                // 数値が自分の権限以上のものでないとアクセスできない。
75                if($this->arrPERMISSION[$admin_path] < $this->authority) {
76                    return AUTH_ERROR;
77                }
78            }
79            return SUCCESS;
80        }
81
82        return ACCESS_ERROR;
83    }
84
85    /* セッションの書き込み */
86    function SetSession($key, $val) {
87        $_SESSION[$key] = $val;
88    }
89
90    /* セッションの読み込み */
91    function GetSession($key) {
92        return $_SESSION[$key];
93    }
94
95    /* セッションIDの取得 */
96    function GetSID() {
97        return $this->sid;
98    }
99
100    /** ユニークIDの取得 **/
101    function getUniqId() {
102        // ユニークIDがセットされていない場合はセットする。
103        if( empty($_SESSION['uniqid']) ) {
104            $this->setUniqId();
105        }
106        return $this->GetSession('uniqid');
107    }
108
109    /** ユニークIDのセット **/
110    function setUniqId() {
111        // 予測されないようにランダム文字列を付与する。
112        $this->SetSession('uniqid', SC_Utils_Ex::sfGetUniqRandomId());
113    }
114
115    /* セッションの破棄 */
116    function EndSession() {
117        // デフォルトは、「PHPSESSID」
118        $sname = session_name();
119        // セッション変数を全て解除する
120        $_SESSION = array();
121        // セッションを切断するにはセッションクッキーも削除する。
122        // Note: セッション情報だけでなくセッションを破壊する。
123        if (isset($_COOKIE[$sname])) {
124            setcookie($sname, '', time()-42000, '/');
125        }
126        // 最終的に、セッションを破壊する
127        session_destroy();
128        // ログに記録する
129        GC_Utils_Ex::gfPrintLog("logout : user=".$this->login_id." auth=".$this->authority." sid=".$this->sid);
130    }
131
132    // 関連セッションのみ破棄する。
133    function logout() {
134        unset($_SESSION['cert']);
135        unset($_SESSION['login_id']);
136        unset($_SESSION['authority']);
137        unset($_SESSION['member_id']);
138        unset($_SESSION['uniqid']);
139        // トランザクショントークンを破棄
140        SC_Helper_Session_Ex::destroyToken();
141        // ログに記録する
142        GC_Utils_Ex::gfPrintLog("logout : user=".$this->login_id." auth=".$this->authority." sid=".$this->sid);
143    }
144}
145?>
Note: See TracBrowser for help on using the repository browser.