oxsession.php

Go to the documentation of this file.
00001 <?php
00002 
00003 DEFINE('_DB_SESSION_HANDLER', getShopBasePath() . 'core/adodblite/session/adodb-session.php');
00004 // Including database session managing class if needed.
00005 if (oxConfig::getInstance()->getConfigParam( 'blAdodbSessionHandler' ) ) {
00006     $oDB = oxDb::getDb();
00007     include_once _DB_SESSION_HANDLER;
00008 }
00009 
00015 class oxSession extends oxSuperCfg
00016 {
00022     protected $_sName = 'sid';
00023 
00029     protected $_sForcedPrefix = 'force_';
00030 
00035     protected  $_sId     = null;
00036 
00042     protected static $_blIsNewSession = false;
00043 
00047     protected static $_instance = null;
00048 
00053     protected static  $_oUser = null;
00054 
00061     protected $_blNewSession = false;
00062 
00068     protected $_blForceNewSession = false;
00069 
00075     protected $_sErrorMsg = null;
00076 
00082     protected $_oBasket = null;
00083 
00089     protected $_oBasketReservations = null;
00090 
00096     protected $_blStarted = false;
00097 
00106     protected $_aRequireSessionWithParams = array(
00107                        'cl' => array (
00108                             'register' => true,
00109                             'account'  => true,
00110                            ),
00111                        'fnc' => array (
00112                            'tobasket'         => true,
00113                            'login_noredirect' => true,
00114                            'tocomparelist'    => true,
00115                            ),
00116                        '_artperpage' => true,
00117                        'ldtype'      => true,
00118                        'listorderby' => true,
00119     );
00120 
00126     protected $_blSidNeeded = null;
00127 
00133     protected $_aPersistentParams = array("actshop", "lang", "currency", "language", "tpllanguage");
00134 
00140     public static function getInstance()
00141     {
00142         if ( defined('OXID_PHP_UNIT')) {
00143             if ( isset( modSession::$unitMOD) && is_object( modSession::$unitMOD)) {
00144                 return modSession::$unitMOD;
00145             }
00146         }
00147         if (!isset(self::$_instance)) {
00148             self::$_instance  = oxNew( 'oxsession' );
00149         }
00150         return self::$_instance;
00151     }
00152 
00158     public function getId()
00159     {
00160         return $this->_sId;
00161     }
00162 
00170     public function setId($sVal)
00171     {
00172         $this->_sId = $sVal;
00173     }
00174 
00182     public function setName($sVal)
00183     {
00184         $this->_sName = $sVal;
00185     }
00186 
00192     public function getForcedName()
00193     {
00194         return $this->_sForcedPrefix . $this->getName();
00195     }
00196 
00202     public function getName()
00203     {
00204         return $this->_sName;
00205     }
00206 
00212     public function start()
00213     {
00214         $myConfig = $this->getConfig();
00215         $sid = null;
00216 
00217         if ( $this->isAdmin() ) {
00218             $this->setName("admin_sid");
00219         } else {
00220             $this->setName("sid");
00221         }
00222 
00223         $sForceSidParam = oxConfig::getParameter($this->getForcedName());
00224         $sSidParam = oxConfig::getParameter($this->getName());
00225 
00226         //forcing sid for SSL<->nonSSL transitions
00227         if ($sForceSidParam) {
00228             $sid = $sForceSidParam;
00229         } elseif ($this->_getSessionUseCookies() && $this->_getCookieSid()) {
00230             $sid = $this->_getCookieSid();
00231         } elseif ($sSidParam) {
00232             $sid = $sSidParam;
00233         }
00234 
00235         //starting session if only we can
00236         if ( $this->_allowSessionStart() ) {
00237 
00238             //creating new sid
00239             if ( !$sid ) {
00240                 self::$_blIsNewSession = true;
00241                 $this->initNewSession();
00242             } else {
00243                 self::$_blIsNewSession = false;
00244                 $this->_setSessionId( $sid );
00245                 $this->_sessionStart();
00246             }
00247 
00248             //special handling for new ZP cluster session, as in that case session_start() regenerates id
00249             if ( $this->_sId != session_id() ) {
00250                 $this->_setSessionId( session_id() );
00251             }
00252 
00253             //checking for swapped client
00254             $blSwapped = $this->_isSwappedClient();
00255             if ( !self::$_blIsNewSession && $blSwapped ) {
00256                 $this->initNewSession();
00257 
00258                 // passing notification about session problems
00259                 if ( $this->_sErrorMsg && $myConfig->getConfigParam( 'iDebug' ) ) {
00260                     oxUtilsView::getInstance()->addErrorToDisplay( oxNew( "oxException", $this->_sErrorMsg ) );
00261                 }
00262             } elseif ( !$blSwapped ) {
00263                 // transferring cookies between hosts
00264                 oxUtilsServer::getInstance()->loadSessionCookies();
00265             }
00266         }
00267     }
00268 
00274     public function getRequestChallengeToken()
00275     {
00276         return preg_replace('/[^a-z0-9]/i', '', oxConfig::getParameter('stoken'));
00277     }
00278 
00284     public function getSessionChallengeToken()
00285     {
00286         $sRet = preg_replace('/[^a-z0-9]/i', '', self::getVar('sess_stoken'));
00287         if (!$sRet) {
00288             $this->_initNewSessionChallenge();
00289             $sRet = self::getVar('sess_stoken');
00290         }
00291         return $sRet;
00292     }
00293 
00300     public function checkSessionChallenge()
00301     {
00302         $sToken = $this->getSessionChallengeToken();
00303         return $sToken && ($sToken == $this->getRequestChallengeToken());
00304     }
00305 
00311     protected function _initNewSessionChallenge()
00312     {
00313         self::setVar('sess_stoken', sprintf('%X', crc32(oxUtilsObject::getInstance()->generateUID())));
00314     }
00315 
00321     protected function _sessionStart()
00322     {
00323         //enforcing no caching when session is started
00324         session_cache_limiter( 'nocache' );
00325 
00326         //cache limiter workaround for AOL browsers
00327         //as suggested at http://ilia.ws/archives/59-AOL-Browser-Woes.html
00328         if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
00329              strpos( $_SERVER['HTTP_USER_AGENT'], 'AOL' ) !== false ) {
00330 
00331             session_cache_limiter(false);
00332             header("Cache-Control: no-store, private, must-revalidate, proxy-revalidate, post-check=0, pre-check=0, max-age=0, s-maxage=0");
00333         }
00334 
00335         $this->_blStarted = @session_start();
00336         if ( !$this->getSessionChallengeToken() ) {
00337             $this->_initNewSessionChallenge();
00338         }
00339 
00340         return $this->_blStarted;
00341     }
00342 
00348     public function initNewSession()
00349     {
00350         // starting session only if it was not started yet
00351         if ( self::$_blIsNewSession ) {
00352             $this->_sessionStart();
00353         }
00354 
00355         //saving persistent params if old session exists
00356         $aPersistent = array();
00357         foreach ( $this->_aPersistentParams as $sParam ) {
00358             if ( ( $sValue = self::getVar( $sParam ) ) ) {
00359                 $aPersistent[$sParam] = $sValue;
00360             }
00361         }
00362 
00363         $this->_setSessionId( $this->_getNewSessionId() );
00364 
00365         //restoring persistent params to session
00366         foreach ( $aPersistent as $sKey => $sParam ) {
00367             self::setVar( $sKey, $aPersistent[$sKey] );
00368         }
00369 
00370         $this->_initNewSessionChallenge();
00371 
00372         // (re)setting actual user agent when initiating new session
00373         self::setVar( "sessionagent", oxUtilsServer::getInstance()->getServerVar( 'HTTP_USER_AGENT' ) );
00374     }
00375 
00381     public function regenerateSessionId()
00382     {
00383         // starting session only if it was not started yet
00384         if ( self::$_blIsNewSession ) {
00385             $this->_sessionStart();
00386 
00387             // (re)setting actual user agent when initiating new session
00388             self::setVar( "sessionagent", oxUtilsServer::getInstance()->getServerVar( 'HTTP_USER_AGENT' ) );
00389         }
00390 
00391         $this->_setSessionId( $this->_getNewSessionId( false ) );
00392         $this->_initNewSessionChallenge();
00393     }
00394 
00403     protected function _getNewSessionId( $blUnset = true )
00404     {
00405         $sOldId = session_id();
00406         session_regenerate_id( ! oxConfig::getInstance()->getConfigParam( 'blAdodbSessionHandler' ) );
00407         $sNewId = session_id();
00408 
00409         if ( $blUnset ) {
00410             session_unset();
00411         }
00412 
00413         if ( oxConfig::getInstance()->getConfigParam( 'blAdodbSessionHandler' ) ) {
00414             $oDB = oxDb::getDb();
00415             $oDB->execute("UPDATE oxsessions SET SessionID = ".$oDB->quote( $sNewId )." WHERE SessionID = ".$oDB->quote( $sOldId ) );
00416         }
00417 
00418         return session_id();
00419     }
00420 
00426     public function freeze()
00427     {
00428         // storing basket ..
00429         self::setVar( $this->_getBasketName(), serialize( $this->getBasket() ) );
00430 
00431         session_write_close();
00432     }
00433 
00439     public function destroy()
00440     {
00441         //session_unset();
00442         unset($_SESSION);
00443         session_destroy();
00444     }
00445 
00453     public static function hasVar( $name )
00454     {
00455         if ( defined( 'OXID_PHP_UNIT' ) ) {
00456             if ( isset( modSession::$unitMOD ) && is_object( modSession::$unitMOD ) ) {
00457                 try{
00458                     $sVal = modSession::getInstance()->getVar( $name );
00459                     return isset( $sVal );
00460                 } catch( Exception $e ) {
00461                     // if exception is thrown, use default
00462                 }
00463             }
00464         }
00465 
00466         return isset($_SESSION[$name]);
00467     }
00468 
00477     public static function setVar( $name, $value)
00478     {
00479         if ( defined( 'OXID_PHP_UNIT' ) ) {
00480             if ( isset( modSession::$unitMOD ) && is_object( modSession::$unitMOD ) ) {
00481                 try{
00482                     return modSession::getInstance()->setVar(  $name, $value );
00483                 } catch( Exception $e ) {
00484                     // if exception is thrown, use default
00485                 }
00486             }
00487         }
00488 
00489         $_SESSION[$name] = $value;
00490         //logger( "set sessionvar : $name -> $value");
00491     }
00492 
00500     public static function getVar( $name )
00501     {
00502         if ( defined( 'OXID_PHP_UNIT' ) ) {
00503             if ( isset( modSession::$unitMOD ) && is_object( modSession::$unitMOD ) ) {
00504                 try{
00505                     return modSession::getInstance()->getVar( $name );
00506                 } catch( Exception $e ) {
00507                     // if exception is thrown, use default
00508                 }
00509             }
00510         }
00511 
00512         if ( isset( $_SESSION[$name] )) {
00513             return $_SESSION[$name];
00514         } else {
00515             return null;
00516         }
00517     }
00518 
00526     public static function deleteVar( $name )
00527     {
00528         if ( defined( 'OXID_PHP_UNIT' ) ) {
00529             if ( isset( modSession::$unitMOD ) && is_object( modSession::$unitMOD ) ) {
00530                 try{
00531                     return modSession::getInstance()->setVar( $name, null );
00532                 } catch( Exception $e ) {
00533                     // if exception is thrown, use default
00534                 }
00535             }
00536         }
00537 
00538         $_SESSION[$name] = null;
00539         //logger( "delete sessionvar : $name");
00540         unset($_SESSION[$name]);
00541     }
00542 
00552     public function sid( $blForceSid = false )
00553     {
00554         $myConfig     = $this->getConfig();
00555         $blUseCookies = $this->_getSessionUseCookies();
00556         $sRet         = '';
00557 
00558         $blDisableSid = oxUtils::getInstance()->isSearchEngine()
00559                         && is_array($myConfig->getConfigParam( 'aCacheViews' ) )
00560                         && !$this->isAdmin();
00561 
00562         //no cookie?
00563         if ( !$blDisableSid && $this->getId() && ($blForceSid || !$blUseCookies || !$this->_getCookieSid())) {
00564             $sRet = ( $blForceSid ? $this->getForcedName() : $this->getName() )."=".$this->getId();
00565         }
00566 
00567         if ($this->isAdmin()) {
00568             // admin mode always has to have token
00569             if ($sRet) {
00570                 $sRet .= '&amp;';
00571             }
00572             $sRet .= 'stoken='.$this->getSessionChallengeToken();
00573         }
00574 
00575         return $sRet;
00576     }
00577 
00583     public function hiddenSid()
00584     {
00585         $sToken = "<input type=\"hidden\" name=\"stoken\" value=\"".$this->getSessionChallengeToken(). "\">";
00586         $sSid   = "<input type=\"hidden\" name=\"".$this->getForcedName()."\" value=\"". $this->getId() . "\">";
00587         return $sToken.$sSid;
00588     }
00589 
00595     public function getBasket()
00596     {
00597         if ( $this->_oBasket === null ) {
00598             $sBasket = self::getVar( $this->_getBasketName() );
00599 
00600             //init oxbasketitem class first
00601             //#1746
00602             oxNew('oxbasketitem');
00603 
00604             $oBasket = ( $sBasket && ( $oBasket = unserialize( $sBasket ) ) ) ? $oBasket : null;
00605 
00606             //#3908
00607             $oEmptyBasket = oxNew('oxbasket');
00608             if ( !$oBasket || ( get_class($oBasket) !== get_class($oEmptyBasket) ) ) {
00609                 $oBasket = $oEmptyBasket;
00610             }
00611 
00612             $this->_validateBasket($oBasket);
00613             $this->setBasket( $oBasket );
00614         }
00615 
00616         return $this->_oBasket;
00617     }
00618 
00626     protected function _validateBasket(oxBasket $oBasket)
00627     {
00628         $aCurrContent = $oBasket->getContents();
00629         if (empty($aCurrContent)) {
00630             return;
00631         }
00632 
00633         $iCurrLang = oxLang::getInstance()->getBaseLanguage();
00634         foreach ($aCurrContent as $oContent) {
00635             if ($oContent->getLanguageId() != $iCurrLang) {
00636                 $oContent->setLanguageId($iCurrLang);
00637             }
00638         }
00639     }
00640 
00648     public function setBasket( $oBasket )
00649     {
00650         // sets basket session object
00651         $this->_oBasket = $oBasket;
00652     }
00653 
00659     public function delBasket()
00660     {
00661         $this->setBasket( null );
00662         self::deleteVar( $this->_getBasketName());
00663     }
00664 
00670     public function isNewSession()
00671     {
00672         return self::$_blIsNewSession;
00673     }
00674 
00681     public function setForceNewSession()
00682     {
00683         $this->_blForceNewSession = true;
00684     }
00685 
00693     public function isSidNeeded( $sUrl = null )
00694     {
00695         if ( $this->_getSessionUseCookies() && $this->_getCookieSid() ) {
00696             // switching from ssl to non ssl or vice versa?
00697             if ( ( strpos( $sUrl, "https:" ) === 0 && !$this->getConfig()->isSsl() ) ||
00698                  ( strpos( $sUrl, "http:" ) === 0 && $this->getConfig()->isSsl() ) ) {
00699                 return true;
00700             }
00701         }
00702 
00703         if ( $sUrl && !$this->getConfig()->isCurrentUrl( $sUrl ) ) {
00704             return true;
00705         } elseif ( $this->_blSidNeeded === null ) {
00706             // setting initial state
00707             $this->_blSidNeeded = false;
00708 
00709             // no SIDs for seach engines
00710             if ( !oxUtils::getInstance()->isSearchEngine() ) {
00711                 // cookie found - SID is not needed
00712                 if ( oxUtilsServer::getInstance()->getOxCookie( $this->getName() ) ) {
00713                     $this->_blSidNeeded = false;
00714                 } elseif ( $this->_forceSessionStart() ) {
00715                     $this->_blSidNeeded = true;
00716                 } else {
00717                     // no cookie, so must check session
00718                     if ( $blSidNeeded = self::getVar( 'blSidNeeded' ) ) {
00719                         $this->_blSidNeeded = true;
00720                     } elseif ( $this->_isSessionRequiredAction() ) {
00721                         $this->_blSidNeeded = true;
00722 
00723                         // storing to session, performance..
00724                         self::setVar( 'blSidNeeded', $this->_blSidNeeded  );
00725                     }
00726                 }
00727             }
00728         }
00729 
00730         return $this->_blSidNeeded;
00731     }
00732 
00744     public function processUrl( $sUrl )
00745     {
00746         $sSid = $this->sid( $this->isSidNeeded( $sUrl ) );
00747         if ($sSid) {
00748             $oStr = getStr();
00749             $aUrlParts = explode( '#', $sUrl );
00750             if ( !$oStr->preg_match('/(\?|&(amp;)?)sid=/i', $aUrlParts[0]) && (false === $oStr->strpos($aUrlParts[0], $sSid))) {
00751                 if (!$oStr->preg_match('/(\?|&(amp;)?)$/', $sUrl)) {
00752                     $aUrlParts[0] .= ( $oStr->strstr( $aUrlParts[0], '?' ) !== false ?  '&amp;' : '?' );
00753                 }
00754                 $aUrlParts[0] .= $sSid . '&amp;';
00755             }
00756             $sUrl = join( '#', $aUrlParts );
00757         }
00758         return $sUrl;
00759     }
00760 
00770     public function getRemoteAccessToken($blGenerateNew = true)
00771     {
00772         $sToken = $this->getVar('_rtoken');
00773         if (!$sToken && $blGenerateNew) {
00774             $sToken = md5(rand() . $this->getId());
00775             $sToken = substr($sToken, 0, 8);
00776             self::setVar('_rtoken', $sToken);
00777         }
00778 
00779         return $sToken;
00780     }
00781 
00788     protected function _forceSessionStart()
00789     {
00790         return ( !oxUtils::getInstance()->isSearchEngine() ) && ( (( bool ) $this->getConfig()->getConfigParam( 'blForceSessionStart' )) || oxConfig::getParameter( "su" ) || $this->_blForceNewSession );
00791     }
00792 
00798     protected function _allowSessionStart()
00799     {
00800         $blAllowSessionStart = true;
00801         $myConfig = oxConfig::getInstance();
00802 
00803         // special handling only in non-admin mode
00804         if ( !$this->isAdmin() ) {
00805             if ( oxUtils::getInstance()->isSearchEngine() || oxConfig::getParameter( 'skipSession' ) ) {
00806                 $blAllowSessionStart = false;
00807             } elseif (oxUtilsServer::getInstance()->getOxCookie( 'oxid_'.$myConfig->getShopId().'_autologin' ) === '1') {
00808                 $blAllowSessionStart = true;
00809             } elseif ( !$this->_forceSessionStart() && !oxUtilsServer::getInstance()->getOxCookie( 'sid_key' ) ) {
00810 
00811                 // session is not needed to start when it is not necessary:
00812                 // - no sid in request and also user executes no session connected action
00813                 // - no cookie set and user executes no session connected action
00814                 if ( !oxUtilsServer::getInstance()->getOxCookie( $this->getName() ) &&
00815                      !( oxConfig::getParameter( $this->getName() ) || oxConfig::getParameter( $this->getForcedName() ) ) &&
00816                      !$this->_isSessionRequiredAction() ) {
00817                     $blAllowSessionStart = false;
00818                 }
00819             }
00820         }
00821 
00822         return $blAllowSessionStart;
00823     }
00824 
00832     protected function _isSwappedClient()
00833     {
00834         $blSwapped = false;
00835         $myUtilsServer = oxUtilsServer::getInstance();
00836 
00837         // check only for non search engines
00838         if ( !oxUtils::getInstance()->isSearchEngine() && !$myUtilsServer->isTrustedClientIp() && !$this->_isValidRemoteAccessToken()) {
00839 
00840             $myConfig = $this->getConfig();
00841 
00842             // checking if session user agent matches actual
00843             $blSwapped = $this->_checkUserAgent( $myUtilsServer->getServerVar( 'HTTP_USER_AGENT' ), self::getVar( 'sessionagent' ) );
00844             if ( !$blSwapped ) {
00845                 if ( $myConfig->getConfigParam( 'blAdodbSessionHandler' ) ) {
00846                     $blSwapped = $this->_checkSid();
00847                 }
00848 
00849                 if ( !$blSwapped ) {
00850                     $blDisableCookieCheck = $myConfig->getConfigParam( 'blDisableCookieCheck' );
00851                     $blUseCookies         = $this->_getSessionUseCookies();
00852                     if ( !$blDisableCookieCheck && $blUseCookies ) {
00853                         $blSwapped = $this->_checkCookies( $myUtilsServer->getOxCookie( 'sid_key' ), self::getVar( "sessioncookieisset" ) );
00854                     }
00855                 }
00856             }
00857         }
00858 
00859         return $blSwapped;
00860     }
00861 
00870     protected function _checkUserAgent( $sAgent, $sExistingAgent )
00871     {
00872         $blCheck = false;
00873 
00874         // processing
00875         $oUtils = oxUtilsServer::getInstance();
00876         $sAgent = $oUtils->processUserAgentInfo( $sAgent );
00877         $sExistingAgent = $oUtils->processUserAgentInfo( $sExistingAgent );
00878 
00879         if ( $sAgent && $sAgent !== $sExistingAgent ) {
00880             if ( $sExistingAgent ) {
00881                 $this->_sErrorMsg = "Different browser ({$sExistingAgent}, {$sAgent}), creating new SID...<br>";
00882             }
00883             $blCheck = true;
00884         }
00885 
00886         return $blCheck;
00887     }
00888 
00894     protected function _checkSid()
00895     {
00896         $oDb = oxDb::getDb();
00897         //matze changed sesskey to SessionID because structure of oxsession changed!!
00898         $sSID = $oDb->getOne("select SessionID from oxsessions where SessionID = ".$oDb->quote( $this->getId() ));
00899 
00900         //2007-05-14
00901         //we check _blNewSession as well as this may be actually new session not written to db yet
00902         if ( !$this->_blNewSession && (!isset( $sSID) || !$sSID)) {
00903             // this means, that this session has expired in the past and someone uses this sid to reactivate it
00904             $this->_sErrorMsg = "Session has expired in the past and someone uses this sid to reactivate it, creating new SID...<br>";
00905             return true;
00906         }
00907         return false;
00908     }
00909 
00919     protected function _checkCookies( $sCookieSid, $aSessCookieSetOnce )
00920     {
00921         $blSwapped = false;
00922         $myConfig  = $this->getConfig();
00923         $sCurrUrl  = $myConfig->isSsl() ? $myConfig->getSslShopUrl() : $myConfig->getShopUrl();
00924 
00925         $blSessCookieSetOnce = false;
00926         if ( is_array($aSessCookieSetOnce) && isset( $aSessCookieSetOnce[$sCurrUrl] ) ) {
00927             $blSessCookieSetOnce = $aSessCookieSetOnce[$sCurrUrl];
00928         }
00929 
00930         //if cookie was there once but now is gone it means we have to reset
00931         if ( $blSessCookieSetOnce && !$sCookieSid ) {
00932             if ( $myConfig->getConfigParam( 'iDebug' ) ) {
00933                 $this->_sErrorMsg  = "Cookie not found, creating new SID...<br>";
00934                 $this->_sErrorMsg .= "Cookie: $sCookieSid<br>";
00935                 $this->_sErrorMsg .= "Session: $blSessCookieSetOnce<br>";
00936                 $this->_sErrorMsg .= "URL: ".$sCurrUrl."<br>";
00937             }
00938             $blSwapped = true;
00939         }
00940 
00941         //if we detect the cookie then set session var for possible later use
00942         if ( $sCookieSid == "oxid" && !$blSessCookieSetOnce ) {
00943             if (!is_array($aSessCookieSetOnce)) {
00944                 $aSessCookieSetOnce = array();
00945             }
00946 
00947             $aSessCookieSetOnce[$sCurrUrl] = "ox_true";
00948             self::setVar( "sessioncookieisset", $aSessCookieSetOnce );
00949         }
00950 
00951         //if we have no cookie then try to set it
00952         if ( !$sCookieSid ) {
00953             oxUtilsServer::getInstance()->setOxCookie( 'sid_key', 'oxid' );
00954         }
00955         return $blSwapped;
00956     }
00957 
00965     protected function _setSessionId($sSessId)
00966     {
00967         //marking this session as new one, as it might be not writen to db yet
00968         if ( $sSessId && session_id() != $sSessId ) {
00969             $this->_blNewSession = true;
00970         }
00971 
00972         session_id( $sSessId );
00973 
00974         $this->setId( $sSessId );
00975 
00976         $blUseCookies = $this->_getSessionUseCookies();
00977 
00978         if ( !$this->_allowSessionStart() ) {
00979             if ( $blUseCookies ) {
00980                 oxUtilsServer::getInstance()->setOxCookie( $this->getName(), null );
00981             }
00982             return;
00983         }
00984 
00985         if ( $blUseCookies ) {
00986             //setting session cookie
00987             oxUtilsServer::getInstance()->setOxCookie( $this->getName(), $sSessId );
00988         }
00989     }
00990 
00996     protected function _getBasketName()
00997     {
00998         $myConfig = $this->getConfig();
00999         if ( $myConfig->getConfigParam( 'blMallSharedBasket' ) == 0 ) {
01000             return $myConfig->getShopId()."_basket";
01001         }
01002         return "basket";
01003     }
01004 
01010     protected function _getCookieSid()
01011     {
01012         return oxUtilsServer::getInstance()->getOxCookie($this->getName());
01013     }
01014 
01021     protected function _getRequireSessionWithParams()
01022     {
01023         $aCfgArray = $this->getConfig()->getConfigParam('aRequireSessionWithParams');
01024         if (is_array($aCfgArray)) {
01025             $aDefault = $this->_aRequireSessionWithParams;
01026             foreach ($aCfgArray as $key => $val) {
01027                 if (!is_array($val) && $val) {
01028                     unset($aDefault[$key]);
01029                 }
01030             }
01031             return array_merge_recursive($aCfgArray, $aDefault);
01032         }
01033         return $this->_aRequireSessionWithParams;
01034     }
01035 
01041     protected function _isSessionRequiredAction()
01042     {
01043         foreach ($this->_getRequireSessionWithParams() as $sParam => $aValues) {
01044             $sValue = oxConfig::getParameter( $sParam );
01045             if (isset($sValue)) {
01046                 if (is_array($aValues)) {
01047                     if (isset($aValues[$sValue]) && $aValues[$sValue]) {
01048                         return true;
01049                     }
01050                 } elseif ($aValues) {
01051                     return true;
01052                 }
01053             }
01054         }
01055 
01056         return ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'POST');
01057     }
01058 
01064     protected function _getSessionUseCookies()
01065     {
01066         return $this->isAdmin() || $this->getConfig()->getConfigParam( 'blSessionUseCookies');
01067     }
01068 
01074     protected function _isValidRemoteAccessToken()
01075     {
01076         $sInputToken = oxConfig::getParameter('rtoken');
01077         $sToken = $this->getRemoteAccessToken(false);
01078         $blTokenEqual = !(bool)strcmp($sInputToken, $sToken);
01079         $blValid = $sInputToken && $blTokenEqual;
01080 
01081         return $blValid;
01082     }
01083 
01089     public function getBasketReservations()
01090     {
01091         if (!$this->_oBasketReservations) {
01092             $this->_oBasketReservations = oxNew('oxBasketReservation');
01093         }
01094         return $this->_oBasketReservations;
01095     }
01096 
01102     public function isHeaderSent()
01103     {
01104         return headers_sent();
01105     }
01106 
01112     public function isSessionStarted()
01113     {
01114         return $this->_blStarted;
01115     }
01116 }