Public Member Functions | |
start ($sessionName=null) | |
getCookie () | |
revalidateCookie () | |
init ($namespace, $sessionName=null) | |
getData ($key='', $clear=false) | |
getSessionId () | |
setSessionId ($id=null) | |
getSessionName () | |
setSessionName ($name) | |
unsetAll () | |
clear () | |
getSessionSaveMethod () | |
getSessionSavePath () | |
useValidateRemoteAddr () | |
useValidateHttpVia () | |
useValidateHttpXForwardedFor () | |
useValidateHttpUserAgent () | |
getValidateHttpUserAgentSkip () | |
validate () | |
getValidatorData () | |
Public Attributes | |
const | VALIDATOR_KEY = '_session_validator_data' |
const | VALIDATOR_HTTP_USER_AGENT_KEY = 'http_user_agent' |
const | VALIDATOR_HTTP_X_FORVARDED_FOR_KEY = 'http_x_forwarded_for' |
const | VALIDATOR_HTTP_VIA_KEY = 'http_via' |
const | VALIDATOR_REMOTE_ADDR_KEY = 'remote_addr' |
Protected Member Functions | |
_validate () |
Definition at line 28 of file Varien.php.
_validate | ( | ) | [protected] |
Validate data
Definition at line 349 of file Varien.php.
00350 { 00351 $sessionData = $this->_data[self::VALIDATOR_KEY]; 00352 $validatorData = $this->getValidatorData(); 00353 00354 if ($this->useValidateRemoteAddr() && $sessionData[self::VALIDATOR_REMOTE_ADDR_KEY] != $validatorData[self::VALIDATOR_REMOTE_ADDR_KEY]) { 00355 return false; 00356 } 00357 if ($this->useValidateHttpVia() && $sessionData[self::VALIDATOR_HTTP_VIA_KEY] != $validatorData[self::VALIDATOR_HTTP_VIA_KEY]) { 00358 return false; 00359 } 00360 if ($this->useValidateHttpXForwardedFor() && $sessionData[self::VALIDATOR_HTTP_X_FORVARDED_FOR_KEY] != $validatorData[self::VALIDATOR_HTTP_X_FORVARDED_FOR_KEY]) { 00361 return false; 00362 } 00363 if ($this->useValidateHttpUserAgent() 00364 && $sessionData[self::VALIDATOR_HTTP_USER_AGENT_KEY] != $validatorData[self::VALIDATOR_HTTP_USER_AGENT_KEY] 00365 && !in_array($validatorData[self::VALIDATOR_HTTP_USER_AGENT_KEY], $this->getValidateHttpUserAgentSkip())) { 00366 return false; 00367 } 00368 00369 return true; 00370 }
clear | ( | ) |
Alias for unsetAll
Reimplemented in Mage_Api_Model_Session, and Mage_Checkout_Model_Session.
Definition at line 246 of file Varien.php.
00247 { 00248 return $this->unsetAll(); 00249 }
getCookie | ( | ) |
Retrieve cookie object
Definition at line 111 of file Varien.php.
00112 { 00113 return Mage::getSingleton('core/cookie'); 00114 }
getData | ( | $ | key = '' , |
|
$ | clear = false | |||
) |
Additional get data with clear mode
string | $key | |
bool | $clear |
Reimplemented from Varien_Object.
Definition at line 175 of file Varien.php.
00176 { 00177 $data = parent::getData($key); 00178 if ($clear && isset($this->_data[$key])) { 00179 unset($this->_data[$key]); 00180 } 00181 return $data; 00182 }
getSessionId | ( | ) |
Retrieve session Id
Reimplemented in Mage_Api_Model_Session.
Definition at line 189 of file Varien.php.
getSessionName | ( | ) |
getSessionSaveMethod | ( | ) |
Retrieve session save method Default files
Reimplemented in Mage_Core_Model_Session_Abstract.
Definition at line 257 of file Varien.php.
getSessionSavePath | ( | ) |
Get sesssion save path
Reimplemented in Mage_Core_Model_Session_Abstract.
Definition at line 267 of file Varien.php.
00268 { 00269 return Mage::getBaseDir('session'); 00270 }
getValidateHttpUserAgentSkip | ( | ) |
Retrieve skip User Agent validation strings (Flash etc)
Reimplemented in Mage_Core_Model_Session_Abstract.
Definition at line 317 of file Varien.php.
00318 { 00319 return array(); 00320 }
getValidatorData | ( | ) |
Retrieve unique user data for validator
Definition at line 377 of file Varien.php.
00378 { 00379 $parts = array( 00380 self::VALIDATOR_REMOTE_ADDR_KEY => '', 00381 self::VALIDATOR_HTTP_VIA_KEY => '', 00382 self::VALIDATOR_HTTP_X_FORVARDED_FOR_KEY => '', 00383 self::VALIDATOR_HTTP_USER_AGENT_KEY => '' 00384 ); 00385 00386 // collect ip data 00387 if (isset($_SERVER['REMOTE_ADDR'])) { 00388 $parts[self::VALIDATOR_REMOTE_ADDR_KEY] = (string)$_SERVER['REMOTE_ADDR']; 00389 } 00390 if (isset($_ENV['HTTP_VIA'])) { 00391 $parts[self::VALIDATOR_HTTP_VIA_KEY] = (string)$_ENV['HTTP_VIA']; 00392 } 00393 if (isset($_ENV['HTTP_X_FORWARDED_FOR'])) { 00394 $parts[self::VALIDATOR_HTTP_X_FORVARDED_FOR_KEY] = (string)$_ENV['HTTP_X_FORWARDED_FOR']; 00395 } 00396 00397 // collect user agent data 00398 if (isset($_SERVER['HTTP_USER_AGENT'])) { 00399 $parts[self::VALIDATOR_HTTP_USER_AGENT_KEY] = (string)$_SERVER['HTTP_USER_AGENT']; 00400 } 00401 00402 return $parts; 00403 }
init | ( | $ | namespace, | |
$ | sessionName = null | |||
) |
Init session with namespace
string | $namespace | |
string | $sessionName |
Reimplemented in Mage_Api_Model_Session, and Mage_Core_Model_Session_Abstract.
Definition at line 151 of file Varien.php.
00152 { 00153 if (!isset($_SESSION)) { 00154 $this->start($sessionName); 00155 } 00156 if (!isset($_SESSION[$namespace])) { 00157 $_SESSION[$namespace] = array(); 00158 } 00159 00160 $this->_data = &$_SESSION[$namespace]; 00161 00162 $this->validate(); 00163 $this->revalidateCookie(); 00164 00165 return $this; 00166 }
revalidateCookie | ( | ) |
Revalidate cookie
Reimplemented in Mage_Api_Model_Session.
Definition at line 121 of file Varien.php.
00122 { 00123 if (!$this->getCookie()->getLifetime()) { 00124 return $this; 00125 } 00126 if (empty($_SESSION['_cookie_revalidate'])) { 00127 $time = time() + round($this->getCookie()->getLifetime() / 4); 00128 $_SESSION['_cookie_revalidate'] = $time; 00129 } 00130 else { 00131 if ($_SESSION['_cookie_revalidate'] < time()) { 00132 if (!headers_sent()) { 00133 $this->getCookie()->set(session_name(), session_id()); 00134 00135 $time = time() + round($this->getCookie()->getLifetime() / 4); 00136 $_SESSION['_cookie_revalidate'] = $time; 00137 } 00138 } 00139 } 00140 00141 return $this; 00142 }
setSessionId | ( | $ | id = null |
) |
Set custom session id
string | $id |
Reimplemented in Mage_Api_Model_Session, and Mage_Core_Model_Session_Abstract.
Definition at line 200 of file Varien.php.
00201 { 00202 if (!is_null($id) && preg_match('#^[0-9a-zA-Z,-]+$#', $id)) { 00203 session_id($id); 00204 } 00205 return $this; 00206 }
setSessionName | ( | $ | name | ) |
start | ( | $ | sessionName = null |
) |
Conigure and start session
string | $sessionName |
Reimplemented in Mage_Api_Model_Session.
Definition at line 42 of file Varien.php.
00043 { 00044 if (isset($_SESSION)) { 00045 return $this; 00046 } 00047 00048 Varien_Profiler::start(__METHOD__.'/setOptions'); 00049 if (is_writable(Mage::getBaseDir('session'))) { 00050 session_save_path($this->getSessionSavePath()); 00051 } 00052 Varien_Profiler::stop(__METHOD__.'/setOptions'); 00053 00054 switch($this->getSessionSaveMethod()) { 00055 case 'db': 00056 ini_set('session.save_handler', 'user'); 00057 $sessionResource = Mage::getResourceSingleton('core/session'); 00058 /* @var $sessionResource Mage_Core_Model_Mysql4_Session */ 00059 $sessionResource->setSaveHandler(); 00060 break; 00061 case 'memcache': 00062 ini_set('session.save_handler', 'memcache'); 00063 session_save_path($this->getSessionSavePath()); 00064 break; 00065 default: 00066 session_module_name('files'); 00067 break; 00068 } 00069 00070 if (Mage::app()->getStore()->isAdmin()) { 00071 $adminSessionLifetime = (int)Mage::getStoreConfig('admin/security/session_cookie_lifetime'); 00072 if ($adminSessionLifetime > 60) { 00073 Mage::getSingleton('core/cookie')->setLifetime($adminSessionLifetime); 00074 } 00075 } 00076 00077 // set session cookie params 00078 session_set_cookie_params( 00079 $this->getCookie()->getLifetime(), 00080 $this->getCookie()->getPath(), 00081 $this->getCookie()->getDomain(), 00082 $this->getCookie()->isSecure(), 00083 $this->getCookie()->getHttponly() 00084 ); 00085 00086 if (!empty($sessionName)) { 00087 $this->setSessionName($sessionName); 00088 } 00089 00090 // potential custom logic for session id (ex. switching between hosts) 00091 $this->setSessionId(); 00092 00093 Varien_Profiler::start(__METHOD__.'/start'); 00094 00095 if ($sessionCacheLimiter = Mage::getConfig()->getNode('global/session_cache_limiter')) { 00096 session_cache_limiter((string)$sessionCacheLimiter); 00097 } 00098 00099 session_start(); 00100 00101 Varien_Profiler::stop(__METHOD__.'/start'); 00102 00103 return $this; 00104 }
unsetAll | ( | ) |
Unset all data
Reimplemented in Mage_Checkout_Model_Session.
Definition at line 235 of file Varien.php.
00236 { 00237 $this->unsetData(); 00238 return $this; 00239 }
useValidateHttpUserAgent | ( | ) |
Use HTTP_USER_AGENT in validator key
Reimplemented in Mage_Core_Model_Session_Abstract.
Definition at line 307 of file Varien.php.
useValidateHttpVia | ( | ) |
Use HTTP_VIA in validator key
Reimplemented in Mage_Core_Model_Session_Abstract.
Definition at line 287 of file Varien.php.
useValidateHttpXForwardedFor | ( | ) |
Use HTTP_X_FORWARDED_FOR in validator key
Reimplemented in Mage_Core_Model_Session_Abstract.
Definition at line 297 of file Varien.php.
useValidateRemoteAddr | ( | ) |
Use REMOTE_ADDR in validator key
Reimplemented in Mage_Core_Model_Session_Abstract.
Definition at line 277 of file Varien.php.
validate | ( | ) |
Validate session
string | $namespace |
Definition at line 328 of file Varien.php.
00329 { 00330 if (!isset($this->_data[self::VALIDATOR_KEY])) { 00331 $this->_data[self::VALIDATOR_KEY] = $this->getValidatorData(); 00332 } 00333 else { 00334 if (!$this->_validate()) { 00335 $this->getCookie()->delete(session_name()); 00336 // throw core session exception 00337 throw new Mage_Core_Model_Session_Exception(''); 00338 } 00339 } 00340 00341 return $this; 00342 }
const VALIDATOR_HTTP_USER_AGENT_KEY = 'http_user_agent' |
Definition at line 31 of file Varien.php.
const VALIDATOR_HTTP_VIA_KEY = 'http_via' |
Definition at line 33 of file Varien.php.
const VALIDATOR_HTTP_X_FORVARDED_FOR_KEY = 'http_x_forwarded_for' |
Definition at line 32 of file Varien.php.
const VALIDATOR_KEY = '_session_validator_data' |
Definition at line 30 of file Varien.php.
const VALIDATOR_REMOTE_ADDR_KEY = 'remote_addr' |
Definition at line 34 of file Varien.php.