Source for file SC_SessionFactory_UseRequest.php
Documentation is available at SC_SessionFactory_UseRequest.php
* This file is part of EC-CUBE
* Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
* http://www.lockon.co.jp/
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
require_once CLASS_REALDIR . 'session/SC_SessionFactory.php';
require_once CLASS_EX_REALDIR . 'helper_extends/SC_Helper_Mobile_Ex.php';
* Cookieを使用せず、リクエストパラメーターによりセッションを継続する設定を行うクラス.
* 必ず SC_SessionFactory クラスを経由してインスタンス化する.
* また, SC_SessionFactory クラスの関数を必ずオーバーライドしている必要がある.
* @package SC_SessionFactory
* @author LOCKON CO.,LTD.
* @version $Id: SC_SessionFactory_UseRequest.php 20970 2011-06-10 10:27:24Z Seasoft $
* PC/モバイルのセッション管理オブジェクトを切り替える
* @return boolean 常にfalseを返す
* dtb_mobile_ext_session_id テーブルを検索してセッションIDを取得する。
* PCサイトでもモバイルサイトでもこのテーブルを利用する.
* @return string|null取得したセッションIDを返す。
if (!preg_match('|^' . ROOT_URLPATH . '(.*)$|', $_SERVER['SCRIPT_NAME'], $matches)) {
$lifetime = $this->state->getLifeTime();
$time = date('Y-m-d H:i:s', time() - $lifetime);
$objQuery = new SC_Query_Ex();
foreach ($_REQUEST as $key => $value) {
$session_id = $objQuery->get('session_id', 'dtb_mobile_ext_session_id',
'param_key = ? AND param_value = ? AND url = ? AND create_date >= ?',
array($key, $value, $url, $time));
if (isset ($session_id)) {
* 外部サイト連携用にセッションIDとパラメーターの組み合わせを保存する。
* @param string $param_key パラメーター名
* @param string $param_value パラメーター値
$objQuery = new SC_Query_Ex();
$lifetime = $this->state->getLifeTime();
$time = date('Y-m-d H:i:s', time() - $lifetime);
$objQuery->delete('dtb_mobile_ext_session_id', 'create_date < ?', array($time));
'param_key' => $param_key,
'param_value' => $param_value,
$objQuery->insert('dtb_mobile_ext_session_id', $arrValues);
* セッションデータが有効かどうかをチェックする。
* @return boolean セッションデータが有効な場合は true、無効な場合は false を返す。
return $this->state->validateSessionData();
* パラメーターから有効なセッションIDを取得する。
* @return string|false取得した有効なセッションIDを返す。
if (!isset ($sessionId)) {
if (!isset ($sessionId)) {
if (!isset ($sessionId)) {
$objSession = new SC_Helper_Session_Ex();
if ($objSession->sfSessRead($sessionId) === null) {
GC_Utils_Ex::gfPrintLog("Non-existent session id : sid=$sessionId");
// セッションIDの受け渡しにクッキーを使用しない。
ini_set('session.use_cookies', '0');
ini_set('session.use_trans_sid', '1');
ini_set('session.use_only_cookies', '0');
// パラメーターから有効なセッションIDを取得する。
* PHP4 では session.use_trans_sid が PHP_INI_PREDIR なので
if (!ini_get('session.use_trans_sid')) {
// セッションIDまたはセッションデータが無効な場合は、セッションIDを再生成
$this->state->inisializeSessionData();
// 新しいセッションIDを付加してリダイレクトする。
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
// GET の場合は同じページにリダイレクトする。
$objMobile = new SC_Helper_Mobile_Ex;
header('Location: ' . $objMobile->gfAddSessionId());
// GET 以外の場合はトップページへリダイレクトする。
header('Location: ' . TOP_URLPATH . '?' . SID);
$this->state->updateExpire();
* セッションデータが設定されているかを判定する.
* $_SESSION[$namespace]の値が配列の場合に
if (isset ($_SESSION[$namespace]) && is_array($_SESSION[$namespace])) {
GC_Utils_Ex::gfPrintLog("NameSpace $namespace not found in session data : sid=" . session_id());
* 取得するデータは$_SESSION[$namespace][$key]となる.
return isset ($_SESSION[$namespace][$key])
? $_SESSION[$namespace][$key]
* $_SESSION[$namespace][$key] = $valueの形で登録される.
$_SESSION[$namespace][$key] = $value;
$date = date('Y/m/d H:i:s', $expire);
GC_Utils_Ex::gfPrintLog("Session expired at $date : sid=" . session_id());
$this->setValue('ip', $_SERVER['REMOTE_ADDR']);
* REMOTE_ADDRとセッション中のIPが同じかどうかを判定する.
if (!empty($_SERVER['REMOTE_ADDR'])
&& $ip === $_SERVER['REMOTE_ADDR']) {
$msg = sprintf('Ip Addr mismatch : %s != %s(expected) : sid=%s',
GC_Utils_Ex::gfPrintLog($msg);
* UserAgentもしくは携帯の機種名を取得する.
$method = 'validate' . $method;
* $_SESSION['pc']=> array(
* ['model'] => "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"
* ['expires'] => 1204699031
* @return LC_UseRequest_State_PC
$this->lifetime = SESSION_LIFETIME;
$this->validate = array('NameSpace', 'Model', 'Ip', 'Expire');
$this->setValue('model', $_SERVER['HTTP_USER_AGENT']);
if (!empty($_SERVER['HTTP_USER_AGENT'])
&& $_SERVER['HTTP_USER_AGENT'] === $ua) {
$msg = sprintf("User agent model mismatch : %s != %s(expected), sid=%s",
GC_Utils_Ex::gfPrintLog($msg);
* $_SESSION['mobile']=> array(
* ['expires'] => 1204699031
* @return LC_UseRequest_State_Mobile
$this->namespace = 'mobile';
$this->lifetime = MOBILE_SESSION_LIFETIME;
$this->validate = array('NameSpace', 'Model', 'Expire');
$this->setValue('model', SC_MobileUserAgent_Ex::getModel());
* セッション中の携帯機種名と、アクセスしてきたブラウザの機種名が同じかどうかを判定する
$modelInSession = $this->getModel();
$model = SC_MobileUserAgent_Ex::getModel();
&& $model === $modelInSession) {
return $this->getValue('phone_id');
$this->setValue('phone_id', SC_MobileUserAgent_Ex::getId());
Documentation generated on Fri, 24 Feb 2012 14:02:57 +0900 by Seasoft
|