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 
00010 class oxSession extends oxSuperCfg
00011 {
00017     protected $_sName = 'sid';
00018 
00024     protected $_sForcedPrefix = 'force_';
00025 
00030     protected  $_sId     = null;
00031 
00037     protected static $_blIsNewSession = false;
00038 
00042     protected static $_instance = null;
00043 
00048     protected static  $_oUser = null;
00049 
00056     protected $_blNewSession = false;
00057 
00063     protected $_blForceNewSession = false;
00064 
00070     protected $_sErrorMsg = null;
00071 
00077     protected $_oBasket = null;
00078 
00084     protected $_oBasketReservations = null;
00085 
00091     protected $_blStarted = false;
00092 
00101     protected $_aRequireSessionWithParams = array(
00102                        'cl' => array (
00103                             'register' => true,
00104                             'account'  => true,
00105                            ),
00106                        'fnc' => array (
00107                            'tobasket'         => true,
00108                            'login_noredirect' => true,
00109                            'tocomparelist'    => true,
00110                            ),
00111                        '_artperpage' => true,
00112                        'ldtype'      => true,
00113                        'listorderby' => true,
00114     );
00115 
00121     protected $_blSidNeeded = null;
00122 
00128     protected $_aPersistentParams = array("actshop", "lang", "currency", "language", "tpllanguage");
00129 
00137     public static function getInstance()
00138     {
00139         return oxRegistry::getSession();
00140     }
00141 
00147     public function getId()
00148     {
00149         return $this->_sId;
00150     }
00151 
00159     public function setId($sVal)
00160     {
00161         $this->_sId = $sVal;
00162     }
00163 
00171     public function setName($sVal)
00172     {
00173         $this->_sName = $sVal;
00174     }
00175 
00181     public function getForcedName()
00182     {
00183         return $this->_sForcedPrefix . $this->getName();
00184     }
00185 
00191     public function getName()
00192     {
00193         return $this->_sName;
00194     }
00195 
00201     public function start()
00202     {
00203         $myConfig = $this->getConfig();
00204         $sid = null;
00205 
00206         if ( $this->isAdmin() ) {
00207             $this->setName("admin_sid");
00208         } else {
00209             $this->setName("sid");
00210         }
00211 
00212         $sForceSidParam = $myConfig->getRequestParameter( $this->getForcedName() );
00213         $sSidParam = $myConfig->getRequestParameter( $this->getName() );
00214 
00215         //forcing sid for SSL<->nonSSL transitions
00216         if ($sForceSidParam) {
00217             $sid = $sForceSidParam;
00218         } elseif ($this->_getSessionUseCookies() && $this->_getCookieSid()) {
00219             $sid = $this->_getCookieSid();
00220         } elseif ($sSidParam) {
00221             $sid = $sSidParam;
00222         }
00223 
00224         //starting session if only we can
00225         if ( $this->_allowSessionStart() ) {
00226 
00227             //creating new sid
00228             if ( !$sid ) {
00229                 self::$_blIsNewSession = true;
00230                 $this->initNewSession();
00231             } else {
00232                 self::$_blIsNewSession = false;
00233                 $this->_setSessionId( $sid );
00234                 $this->_sessionStart();
00235             }
00236 
00237             //special handling for new ZP cluster session, as in that case session_start() regenerates id
00238             if ( $this->_sId != session_id() ) {
00239                 $this->_setSessionId( session_id() );
00240             }
00241 
00242             //checking for swapped client
00243             $blSwapped = $this->_isSwappedClient();
00244             if ( !self::$_blIsNewSession && $blSwapped ) {
00245                 $this->initNewSession();
00246 
00247                 // passing notification about session problems
00248                 if ( $this->_sErrorMsg && $myConfig->getConfigParam( 'iDebug' ) ) {
00249                     oxRegistry::get("oxUtilsView")->addErrorToDisplay( oxNew( "oxException", $this->_sErrorMsg ) );
00250                 }
00251             } elseif ( !$blSwapped ) {
00252                 // transferring cookies between hosts
00253                 oxRegistry::get("oxUtilsServer")->loadSessionCookies();
00254             }
00255         }
00256     }
00257 
00263     public function getRequestChallengeToken()
00264     {
00265         return preg_replace('/[^a-z0-9]/i', '', $this->getConfig()->getRequestParameter( 'stoken') );
00266     }
00267 
00273     public function getSessionChallengeToken()
00274     {
00275         $sRet = preg_replace('/[^a-z0-9]/i', '', $this->getVariable( 'sess_stoken' ) );
00276         if (!$sRet) {
00277             $this->_initNewSessionChallenge();
00278             $sRet = $this->getVariable( 'sess_stoken' );
00279         }
00280         return $sRet;
00281     }
00282 
00289     public function checkSessionChallenge()
00290     {
00291         $sToken = $this->getSessionChallengeToken();
00292         return $sToken && ($sToken == $this->getRequestChallengeToken());
00293     }
00294 
00300     protected function _initNewSessionChallenge()
00301     {
00302         $this->setVariable('sess_stoken', sprintf('%X', crc32(oxUtilsObject::getInstance()->generateUID())));
00303     }
00304 
00310     protected function _sessionStart()
00311     {
00312         $blSetNoCache = true;
00313         if ( $blSetNoCache ) {
00314             //enforcing no caching when session is started
00315             session_cache_limiter( 'nocache' );
00316 
00317             //cache limiter workaround for AOL browsers
00318             //as suggested at http://ilia.ws/archives/59-AOL-Browser-Woes.html
00319             if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
00320                  strpos( $_SERVER['HTTP_USER_AGENT'], 'AOL' ) !== false ) {
00321 
00322                 session_cache_limiter(false);
00323                 header("Cache-Control: no-store, private, must-revalidate, proxy-revalidate, post-check=0, pre-check=0, max-age=0, s-maxage=0");
00324             }
00325         }
00326 
00327         // Including database session managing class if needed.
00328         if (oxRegistry::getConfig()->getConfigParam( 'blAdodbSessionHandler' ) ) {
00329             $oDB = oxDb::getDb();
00330             include_once _DB_SESSION_HANDLER;
00331         }
00332 
00333         $this->_blStarted = @session_start();
00334         if ( !$this->getSessionChallengeToken() ) {
00335             $this->_initNewSessionChallenge();
00336         }
00337 
00338         return $this->_blStarted;
00339     }
00340 
00346     public function initNewSession()
00347     {
00348         // starting session only if it was not started yet
00349         if ( self::$_blIsNewSession ) {
00350             $this->_sessionStart();
00351         }
00352 
00353         //saving persistent params if old session exists
00354         $aPersistent = array();
00355         foreach ( $this->_aPersistentParams as $sParam ) {
00356             if ( ( $sValue = $this->getVariable( $sParam ) ) ) {
00357                 $aPersistent[$sParam] = $sValue;
00358             }
00359         }
00360 
00361         $this->_setSessionId( $this->_getNewSessionId() );
00362 
00363         //restoring persistent params to session
00364         foreach ( $aPersistent as $sKey => $sParam ) {
00365             $this->setVariable( $sKey, $aPersistent[$sKey] );
00366         }
00367 
00368         $this->_initNewSessionChallenge();
00369 
00370         // (re)setting actual user agent when initiating new session
00371         $this->setVariable( "sessionagent", oxRegistry::get("oxUtilsServer")->getServerVar( 'HTTP_USER_AGENT' ) );
00372     }
00373 
00379     public function regenerateSessionId()
00380     {
00381         // starting session only if it was not started yet
00382         if ( self::$_blIsNewSession ) {
00383             $this->_sessionStart();
00384 
00385             // (re)setting actual user agent when initiating new session
00386             $this->setVariable( "sessionagent", oxRegistry::get("oxUtilsServer")->getServerVar( 'HTTP_USER_AGENT' ) );
00387         }
00388 
00389         $this->_setSessionId( $this->_getNewSessionId( false ) );
00390         $this->_initNewSessionChallenge();
00391     }
00392 
00401     protected function _getNewSessionId( $blUnset = true )
00402     {
00403         $sOldId = session_id();
00404         @session_regenerate_id( ! oxRegistry::getConfig()->getConfigParam( 'blAdodbSessionHandler' ) );
00405         $sNewId = session_id();
00406 
00407         if ( $blUnset ) {
00408             session_unset();
00409         }
00410 
00411         if ( oxRegistry::getConfig()->getConfigParam( 'blAdodbSessionHandler' ) ) {
00412             $oDB = oxDb::getDb();
00413             $oDB->execute("UPDATE oxsessions SET SessionID = ".$oDB->quote( $sNewId )." WHERE SessionID = ".$oDB->quote( $sOldId ) );
00414         }
00415 
00416         return session_id();
00417     }
00418 
00424     public function freeze()
00425     {
00426         // storing basket ..
00427         $this->setVariable( $this->_getBasketName(), serialize( $this->getBasket() ) );
00428 
00429         session_write_close();
00430     }
00431 
00437     public function destroy()
00438     {
00439         //session_unset();
00440         unset($_SESSION);
00441         session_destroy();
00442     }
00443 
00453     public static function hasVar( $name )
00454     {
00455         return oxRegistry::getSession()->hasVariable( $name );
00456     }
00457 
00465     public function hasVariable( $name )
00466     {
00467         if ( defined( 'OXID_PHP_UNIT' ) ) {
00468             if ( isset( modSession::$unitMOD ) && is_object( modSession::$unitMOD ) ) {
00469                 try {
00470                     $sVal = modSession::getInstance()->getVar( $name );
00471                     return isset( $sVal );
00472                 } catch( Exception $e ) {
00473                     // if exception is thrown, use default
00474                 }
00475             }
00476         }
00477 
00478         return isset( $_SESSION[$name] );
00479     }
00480 
00491     public static function setVar( $name, $value )
00492     {
00493 
00494         return oxRegistry::getSession()->setVariable( $name, $value );
00495     }
00496 
00505     public function setVariable( $name, $value )
00506     {
00507         if ( defined( 'OXID_PHP_UNIT' ) ) {
00508             if ( isset( modSession::$unitMOD ) && is_object( modSession::$unitMOD ) ) {
00509                 try{
00510                     return modSession::getInstance()->setVar( $name, $value );
00511                 } catch( Exception $e ) {
00512                     // if exception is thrown, use default
00513                 }
00514             }
00515         }
00516 
00517         $_SESSION[$name] = $value;
00518         //logger( "set sessionvar : $name -> $value");
00519     }
00520 
00530     public static function getVar( $name )
00531     {
00532         return oxRegistry::getSession()->getVariable( $name );
00533     }
00534 
00542     public function getVariable( $name )
00543     {
00544         if ( defined( 'OXID_PHP_UNIT' ) ) {
00545             if ( isset( modSession::$unitMOD ) && is_object( modSession::$unitMOD ) ) {
00546                 try{
00547                     return modSession::getInstance()->getVar( $name );
00548                 } catch( Exception $e ) {
00549                     // if exception is thrown, use default
00550                 }
00551             }
00552         }
00553 
00554         if ( isset( $_SESSION[$name] )) {
00555             return $_SESSION[$name];
00556         } else {
00557             return null;
00558         }
00559     }
00560 
00570     public static function deleteVar( $name )
00571     {
00572         oxRegistry::getSession()->deleteVariable( $name );
00573     }
00574 
00582     public function deleteVariable( $name )
00583     {
00584         if ( defined( 'OXID_PHP_UNIT' ) ) {
00585             if ( isset( modSession::$unitMOD ) && is_object( modSession::$unitMOD ) ) {
00586                 try{
00587                     return modSession::getInstance()->setVar( $name, null );
00588                 } catch( Exception $e ) {
00589                     // if exception is thrown, use default
00590                 }
00591             }
00592         }
00593 
00594         $_SESSION[$name] = null;
00595         //logger( "delete sessionvar : $name");
00596         unset( $_SESSION[$name] );
00597     }
00598 
00608     public function sid( $blForceSid = false )
00609     {
00610         $myConfig     = $this->getConfig();
00611         $blUseCookies = $this->_getSessionUseCookies();
00612         $sRet         = '';
00613 
00614         $blDisableSid = oxRegistry::getUtils()->isSearchEngine()
00615                         && is_array($myConfig->getConfigParam( 'aCacheViews' ) )
00616                         && !$this->isAdmin();
00617 
00618         //no cookie?
00619         if (!$blDisableSid && $this->getId() && ( $blForceSid || !$blUseCookies || !$this->_getCookieSid())) {
00620             $sRet = ( $blForceSid ? $this->getForcedName() : $this->getName() )."=".$this->getId();
00621         }
00622 
00623         if ($this->isAdmin()) {
00624             // admin mode always has to have token
00625             if ($sRet) {
00626                 $sRet .= '&amp;';
00627             }
00628             $sRet .= 'stoken='.$this->getSessionChallengeToken();
00629         }
00630 
00631         return $sRet;
00632     }
00633 
00639     public function hiddenSid()
00640     {
00641         $sSid = $sToken = '';
00642         if ($this->isSidNeeded()) {
00643              $sSid   = "<input type=\"hidden\" name=\"".$this->getForcedName()."\" value=\"". $this->getId() . "\" />";
00644         }
00645         if ($this->getId()) {
00646             $sToken = "<input type=\"hidden\" name=\"stoken\" value=\"".$this->getSessionChallengeToken(). "\" />";
00647         }
00648         return $sToken.$sSid;
00649     }
00650 
00656     public function getBasket()
00657     {
00658         if ( $this->_oBasket === null ) {
00659             $sBasket = $this->getVariable( $this->_getBasketName() );
00660 
00661             //init oxbasketitem class first
00662             //#1746
00663             oxNew('oxbasketitem');
00664 
00665             $oBasket = ( $sBasket && ( $oBasket = unserialize( $sBasket ) ) ) ? $oBasket : null;
00666 
00667             //#3908
00668             $oEmptyBasket = oxNew('oxbasket');
00669             if ( !$oBasket || ( get_class($oBasket) !== get_class($oEmptyBasket) ) ) {
00670                 $oBasket = $oEmptyBasket;
00671             }
00672 
00673             $this->_validateBasket($oBasket);
00674             $this->setBasket( $oBasket );
00675         }
00676 
00677         return $this->_oBasket;
00678     }
00679 
00687     protected function _validateBasket(oxBasket $oBasket)
00688     {
00689         $aCurrContent = $oBasket->getContents();
00690         if (empty($aCurrContent)) {
00691             return;
00692         }
00693 
00694         $iCurrLang = oxRegistry::getLang()->getBaseLanguage();
00695         foreach ($aCurrContent as $oContent) {
00696             if ($oContent->getLanguageId() != $iCurrLang) {
00697                 $oContent->setLanguageId($iCurrLang);
00698             }
00699         }
00700     }
00701 
00709     public function setBasket( $oBasket )
00710     {
00711         // sets basket session object
00712         $this->_oBasket = $oBasket;
00713     }
00714 
00720     public function delBasket()
00721     {
00722         $this->setBasket( null );
00723         $this->deleteVariable( $this->_getBasketName());
00724     }
00725 
00731     public function isNewSession()
00732     {
00733         return self::$_blIsNewSession;
00734     }
00735 
00742     public function setForceNewSession()
00743     {
00744         $this->_blForceNewSession = true;
00745     }
00746 
00754     public function isSidNeeded( $sUrl = null )
00755     {
00756         if ($this->isAdmin()) {
00757             return true;
00758         }
00759 
00760         $oConfig = $this->getConfig();
00761 
00762         if ( !$this->_getSessionUseCookies() || ( $sUrl && $this->_getCookieSid() && !$oConfig->isCurrentProtocol($sUrl) ) ) {
00763             // switching from ssl to non ssl or vice versa?
00764             return true;
00765         }
00766 
00767         if ( $sUrl && !$oConfig->isCurrentUrl( $sUrl ) ) {
00768             return true;
00769         } elseif ( $this->_blSidNeeded === null ) {
00770             // setting initial state
00771             $this->_blSidNeeded = false;
00772 
00773             // no SIDs for seach engines
00774             if ( !oxRegistry::getUtils()->isSearchEngine() ) {
00775                 // cookie found - SID is not needed
00776                 if ( oxRegistry::get("oxUtilsServer")->getOxCookie( $this->getName() ) ) {
00777                     $this->_blSidNeeded = false;
00778                 } elseif ( $this->_forceSessionStart() ) {
00779                     $this->_blSidNeeded = true;
00780                 } else {
00781                     // no cookie, so must check session
00782                     if ( $blSidNeeded = $this->getVariable( 'blSidNeeded' ) ) {
00783                         $this->_blSidNeeded = true;
00784                     } elseif ( $this->_isSessionRequiredAction() ) {
00785 
00786                         if (!count($_COOKIE)) {
00787                             $this->_blSidNeeded = true;
00788 
00789                             // storing to session, performance..
00790                             $this->setVariable( 'blSidNeeded', $this->_blSidNeeded  );
00791                         }
00792                     }
00793                 }
00794             }
00795         }
00796 
00797         return $this->_blSidNeeded;
00798     }
00799 
00811     public function processUrl( $sUrl )
00812     {
00813         $blSid = $this->isSidNeeded( $sUrl );
00814 
00815         if ($blSid) {
00816             $sSid = $this->sid( $blSid );
00817 
00818             if ($sSid) {
00819 
00820                 $oStr = getStr();
00821                 $aUrlParts = explode( '#', $sUrl );
00822                 if ( !$oStr->preg_match('/(\?|&(amp;)?)sid=/i', $aUrlParts[0]) && (false === $oStr->strpos($aUrlParts[0], $sSid))) {
00823                     if (!$oStr->preg_match('/(\?|&(amp;)?)$/', $sUrl)) {
00824                         $aUrlParts[0] .= ( $oStr->strstr( $aUrlParts[0], '?' ) !== false ?  '&amp;' : '?' );
00825                     }
00826                     $aUrlParts[0] .= $sSid . '&amp;';
00827                 }
00828                 $sUrl = join( '#', $aUrlParts );
00829             }
00830         }
00831         return $sUrl;
00832     }
00833 
00843     public function getRemoteAccessToken($blGenerateNew = true)
00844     {
00845         $sToken = $this->getVar('_rtoken');
00846         if (!$sToken && $blGenerateNew) {
00847             $sToken = md5(rand() . $this->getId());
00848             $sToken = substr($sToken, 0, 8);
00849             $this->setVariable( '_rtoken', $sToken );
00850         }
00851 
00852         return $sToken;
00853     }
00854 
00861     protected function _forceSessionStart()
00862     {
00863         return ( !oxRegistry::getUtils()->isSearchEngine() ) && ( (( bool ) $this->getConfig()->getConfigParam( 'blForceSessionStart' )) || $this->getConfig()->getRequestParameter( "su" ) || $this->_blForceNewSession );
00864     }
00865 
00871     protected function _allowSessionStart()
00872     {
00873         $blAllowSessionStart = true;
00874         $myConfig = $this->getConfig();
00875 
00876         // special handling only in non-admin mode
00877         if ( !$this->isAdmin() ) {
00878             if ( oxRegistry::getUtils()->isSearchEngine() || $myConfig->getRequestParameter( 'skipSession' ) ) {
00879                 $blAllowSessionStart = false;
00880             } elseif (oxRegistry::get("oxUtilsServer")->getOxCookie( 'oxid_'.$myConfig->getShopId().'_autologin' ) === '1') {
00881                 $blAllowSessionStart = true;
00882             } elseif ( !$this->_forceSessionStart() && !oxRegistry::get("oxUtilsServer")->getOxCookie( 'sid_key' ) ) {
00883 
00884                 // session is not needed to start when it is not necessary:
00885                 // - no sid in request and also user executes no session connected action
00886                 // - no cookie set and user executes no session connected action
00887                 if ( !oxRegistry::get("oxUtilsServer")->getOxCookie( $this->getName() ) &&
00888                      !( $myConfig->getRequestParameter( $this->getName() ) || $myConfig->getRequestParameter( $this->getForcedName() ) ) &&
00889                      !$this->_isSessionRequiredAction() ) {
00890                     $blAllowSessionStart = false;
00891                 }
00892             }
00893         }
00894 
00895         return $blAllowSessionStart;
00896     }
00897 
00905     protected function _isSwappedClient()
00906     {
00907         $blSwapped = false;
00908         $myUtilsServer = oxRegistry::get("oxUtilsServer");
00909 
00910         // check only for non search engines
00911         if ( !oxRegistry::getUtils()->isSearchEngine() && !$myUtilsServer->isTrustedClientIp() && !$this->_isValidRemoteAccessToken()) {
00912 
00913             $myConfig = $this->getConfig();
00914 
00915             // checking if session user agent matches actual
00916             $blSwapped = $this->_checkUserAgent( $myUtilsServer->getServerVar( 'HTTP_USER_AGENT' ), $this->getVariable( 'sessionagent' ) );
00917             if ( !$blSwapped ) {
00918                 if ( $myConfig->getConfigParam( 'blAdodbSessionHandler' ) ) {
00919                     $blSwapped = $this->_checkSid();
00920                 }
00921 
00922                 if ( !$blSwapped ) {
00923                     $blDisableCookieCheck = $myConfig->getConfigParam( 'blDisableCookieCheck' );
00924                     $blUseCookies         = $this->_getSessionUseCookies();
00925                     if ( !$blDisableCookieCheck && $blUseCookies ) {
00926                         $blSwapped = $this->_checkCookies( $myUtilsServer->getOxCookie( 'sid_key' ), $this->getVariable( "sessioncookieisset" ) );
00927                     }
00928                 }
00929             }
00930         }
00931 
00932         return $blSwapped;
00933     }
00934 
00943     protected function _checkUserAgent( $sAgent, $sExistingAgent )
00944     {
00945         $blCheck = false;
00946 
00947         // processing
00948         $oUtils = oxRegistry::get("oxUtilsServer");
00949         $sAgent = $oUtils->processUserAgentInfo( $sAgent );
00950         $sExistingAgent = $oUtils->processUserAgentInfo( $sExistingAgent );
00951 
00952         if ( $sAgent && $sAgent !== $sExistingAgent ) {
00953             if ( $sExistingAgent ) {
00954                 $this->_sErrorMsg = "Different browser ({$sExistingAgent}, {$sAgent}), creating new SID...<br>";
00955             }
00956             $blCheck = true;
00957         }
00958 
00959         return $blCheck;
00960     }
00961 
00967     protected function _checkSid()
00968     {
00969         $oDb = oxDb::getDb();
00970         //matze changed sesskey to SessionID because structure of oxsession changed!!
00971         $sSID = $oDb->getOne("select SessionID from oxsessions where SessionID = ".$oDb->quote( $this->getId() ));
00972 
00973         //2007-05-14
00974         //we check _blNewSession as well as this may be actually new session not written to db yet
00975         if ( !$this->_blNewSession && (!isset( $sSID) || !$sSID)) {
00976             // this means, that this session has expired in the past and someone uses this sid to reactivate it
00977             $this->_sErrorMsg = "Session has expired in the past and someone uses this sid to reactivate it, creating new SID...<br>";
00978             return true;
00979         }
00980         return false;
00981     }
00982 
00992     protected function _checkCookies( $sCookieSid, $aSessCookieSetOnce )
00993     {
00994         $blSwapped = false;
00995         $myConfig  = $this->getConfig();
00996         $sCurrUrl  = $myConfig->isSsl() ? $myConfig->getSslShopUrl() : $myConfig->getShopUrl();
00997 
00998         $blSessCookieSetOnce = false;
00999         if ( is_array($aSessCookieSetOnce) && isset( $aSessCookieSetOnce[$sCurrUrl] ) ) {
01000             $blSessCookieSetOnce = $aSessCookieSetOnce[$sCurrUrl];
01001         }
01002 
01003         //if cookie was there once but now is gone it means we have to reset
01004         if ( $blSessCookieSetOnce && !$sCookieSid ) {
01005             if ( $myConfig->getConfigParam( 'iDebug' ) ) {
01006                 $this->_sErrorMsg  = "Cookie not found, creating new SID...<br>";
01007                 $this->_sErrorMsg .= "Cookie: $sCookieSid<br>";
01008                 $this->_sErrorMsg .= "Session: $blSessCookieSetOnce<br>";
01009                 $this->_sErrorMsg .= "URL: ".$sCurrUrl."<br>";
01010             }
01011             $blSwapped = true;
01012         }
01013 
01014         //if we detect the cookie then set session var for possible later use
01015         if ( $sCookieSid == "oxid" && !$blSessCookieSetOnce ) {
01016             if (!is_array($aSessCookieSetOnce)) {
01017                 $aSessCookieSetOnce = array();
01018             }
01019 
01020             $aSessCookieSetOnce[$sCurrUrl] = "ox_true";
01021             $this->setVariable( "sessioncookieisset", $aSessCookieSetOnce );
01022         }
01023 
01024         //if we have no cookie then try to set it
01025         if ( !$sCookieSid ) {
01026             oxRegistry::get("oxUtilsServer")->setOxCookie( 'sid_key', 'oxid' );
01027         }
01028         return $blSwapped;
01029     }
01030 
01038     protected function _setSessionId($sSessId)
01039     {
01040         //marking this session as new one, as it might be not writen to db yet
01041         if ( $sSessId && session_id() != $sSessId ) {
01042             $this->_blNewSession = true;
01043         }
01044 
01045         session_id( $sSessId );
01046 
01047         $this->setId( $sSessId );
01048 
01049         $blUseCookies = $this->_getSessionUseCookies();
01050 
01051         if ( !$this->_allowSessionStart() ) {
01052             if ( $blUseCookies ) {
01053                 oxRegistry::get("oxUtilsServer")->setOxCookie( $this->getName(), null );
01054             }
01055             return;
01056         }
01057 
01058         if ( $blUseCookies ) {
01059             //setting session cookie
01060             oxRegistry::get("oxUtilsServer")->setOxCookie( $this->getName(), $sSessId );
01061         }
01062     }
01063 
01069     protected function _getBasketName()
01070     {
01071         $myConfig = $this->getConfig();
01072         if ( $myConfig->getConfigParam( 'blMallSharedBasket' ) == 0 ) {
01073             return $myConfig->getShopId()."_basket";
01074         }
01075         return "basket";
01076     }
01077 
01083     protected function _getCookieSid()
01084     {
01085         return oxRegistry::get("oxUtilsServer")->getOxCookie($this->getName());
01086     }
01087 
01094     protected function _getRequireSessionWithParams()
01095     {
01096         $aCfgArray = $this->getConfig()->getConfigParam('aRequireSessionWithParams');
01097         if (is_array($aCfgArray)) {
01098             $aDefault = $this->_aRequireSessionWithParams;
01099             foreach ($aCfgArray as $key => $val) {
01100                 if (!is_array($val) && $val) {
01101                     unset($aDefault[$key]);
01102                 }
01103             }
01104             return array_merge_recursive($aCfgArray, $aDefault);
01105         }
01106         return $this->_aRequireSessionWithParams;
01107     }
01108 
01114     protected function _isSessionRequiredAction()
01115     {
01116         foreach ($this->_getRequireSessionWithParams() as $sParam => $aValues) {
01117             $sValue = $this->getConfig()->getRequestParameter( $sParam );
01118             if (isset($sValue)) {
01119                 if (is_array($aValues)) {
01120                     if (isset($aValues[$sValue]) && $aValues[$sValue]) {
01121                         return true;
01122                     }
01123                 } elseif ($aValues) {
01124                     return true;
01125                 }
01126             }
01127         }
01128 
01129         return ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'POST');
01130     }
01131 
01137     protected function _getSessionUseCookies()
01138     {
01139         return $this->isAdmin() || $this->getConfig()->getConfigParam( 'blSessionUseCookies');
01140     }
01141 
01147     protected function _isValidRemoteAccessToken()
01148     {
01149         $sInputToken = $this->getConfig()->getRequestParameter( 'rtoken' );
01150         $sToken = $this->getRemoteAccessToken(false);
01151         $blTokenEqual = !(bool)strcmp($sInputToken, $sToken);
01152         $blValid = $sInputToken && $blTokenEqual;
01153 
01154         return $blValid;
01155     }
01156 
01162     public function getBasketReservations()
01163     {
01164         if (!$this->_oBasketReservations) {
01165             $this->_oBasketReservations = oxNew('oxBasketReservation');
01166         }
01167         return $this->_oBasketReservations;
01168     }
01169 
01175     public function isHeaderSent()
01176     {
01177         return headers_sent();
01178     }
01179 
01185     public function isSessionStarted()
01186     {
01187         return $this->_blStarted;
01188     }
01189 
01190 
01191 }