source: branches/version-2_12-dev/data/class/SC_Session.php @ 22567

Revision 22567, 4.2 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

  • 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-2013 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    /** ログインユーザ名 */
29    var $login_id;
30
31    /** ユーザ権限 */
32    var $authority;
33
34    /** 認証文字列(認証成功の判定に使用) */
35    var $cert;
36
37    /** セッションID */
38    var $sid;
39
40    /** ログインユーザの主キー */
41    var $member_id;
42
43    /** ページ遷移の正当性チェックに使用 */
44    var $uniqid;
45
46    /* コンストラクタ */
47    function __construct()
48    {
49        // セッション情報の保存
50        if (isset($_SESSION['cert'])) {
51            $this->sid = session_id();
52            $this->cert = $_SESSION['cert'];
53            $this->login_id  = $_SESSION['login_id'];
54            // 管理者:0, 店舗オーナー:1, 閲覧:2, 販売担当:3 (XXX 現状 0, 1 を暫定実装。2, 3 は未実装。)
55            $this->authority = $_SESSION['authority'];
56            $this->member_id = $_SESSION['member_id'];
57            if (isset($_SESSION['uniq_id'])) {
58                $this->uniqid    = $_SESSION['uniq_id'];
59            }
60
61            // ログに記録する
62            GC_Utils_Ex::gfPrintLog('access : user='.$this->login_id.' auth='.$this->authority.' sid='.$this->sid);
63        } else {
64            // ログに記録する
65            GC_Utils_Ex::gfPrintLog('access error.');
66        }
67    }
68    /* 認証成功の判定 */
69    function IsSuccess()
70    {
71        if ($this->cert == CERT_STRING) {
72            $masterData = new SC_DB_MasterData_Ex();
73            $admin_path = preg_replace('/\/+/', '/', $_SERVER['SCRIPT_NAME']);
74            $arrPERMISSION = $masterData->getMasterData('mtb_permission');
75            if (isset($arrPERMISSION[$admin_path])) {
76                // 数値が自分の権限以上のものでないとアクセスできない。
77                if ($arrPERMISSION[$admin_path] < $this->authority) {
78                    return AUTH_ERROR;
79                }
80            }
81            return SUCCESS;
82        }
83
84        return ACCESS_ERROR;
85    }
86
87    /* セッションの書き込み */
88    function SetSession($key, $val)
89    {
90        $_SESSION[$key] = $val;
91    }
92
93    /* セッションの読み込み */
94    function GetSession($key)
95    {
96        return $_SESSION[$key];
97    }
98
99    /* セッションIDの取得 */
100    function GetSID()
101    {
102        return $this->sid;
103    }
104
105    /** ユニークIDの取得 **/
106    function getUniqId()
107    {
108        // ユニークIDがセットされていない場合はセットする。
109        if (empty($_SESSION['uniqid'])) {
110            $this->setUniqId();
111        }
112        return $this->GetSession('uniqid');
113    }
114
115    /** ユニークIDのセット **/
116    function setUniqId()
117    {
118        // 予測されないようにランダム文字列を付与する。
119        $this->SetSession('uniqid', SC_Utils_Ex::sfGetUniqRandomId());
120    }
121
122    // 関連セッションのみ破棄する。
123    function logout()
124    {
125        unset($_SESSION['cert']);
126        unset($_SESSION['login_id']);
127        unset($_SESSION['authority']);
128        unset($_SESSION['member_id']);
129        unset($_SESSION['uniqid']);
130        // トランザクショントークンを破棄
131        SC_Helper_Session_Ex::destroyToken();
132        // ログに記録する
133        GC_Utils_Ex::gfPrintLog('logout : user='.$this->login_id.' auth='.$this->authority.' sid='.$this->sid);
134    }
135}
Note: See TracBrowser for help on using the repository browser.