/html/data/class/SC_Session.php

https://github.com/nanasess/ec-azure · PHP · 144 lines · 75 code · 17 blank · 52 comment · 9 complexity · 7a1635b9c56fe5eabe8cbf7a03762c99 MD5 · raw file

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