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

Revision 20384, 4.6 KB checked in by nanasess, 13 years ago (diff)

#812(トランザクションIDの自動生成/自動検証)

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