Skip to content

Instantly share code, notes, and snippets.

@piotrekkaminski
Created April 6, 2015 21:41
Show Gist options
  • Save piotrekkaminski/14f49b6ddcb69640d697 to your computer and use it in GitHub Desktop.
Save piotrekkaminski/14f49b6ddcb69640d697 to your computer and use it in GitHub Desktop.
MPERF-7015: Session Cookies not stored for shop on root (2nd level) domain
diff --git a/app/code/core/Mage/Core/Model/Session/Abstract.php b/app/code/core/Mage/Core/Model/Session/Abstract.php
index 4d2bf60..c580932 100644
--- a/app/code/core/Mage/Core/Model/Session/Abstract.php
+++ b/app/code/core/Mage/Core/Model/Session/Abstract.php
@@ -566,14 +566,24 @@ public function renewSession()
{
$this->getCookie()->delete($this->getSessionName());
$this->regenerateSessionId();
+ $this->_deleteCookiesForSameParentDomain();
+ return $this;
+ }
+
+ /**
+ * Delete Session Cookies For Same Parent Domain
+ *
+ * @return Mage_Core_Model_Session_Abstract
+ */
+ protected function _deleteCookiesForSameParentDomain()
+ {
$sessionHosts = $this->getSessionHosts();
- $currentCookieDomain = $this->getCookie()->getDomain();
+ $cookieDomainWithoutLeadDot = ltrim($this->getCookie()->getDomain(), '.');
if (is_array($sessionHosts)) {
- foreach (array_keys($sessionHosts) as $host) {
- // Delete cookies with the same name for parent domains
- if (strpos($currentCookieDomain, $host) > 0) {
- $this->getCookie()->delete($this->getSessionName(), null, $host);
+ foreach (array_keys($sessionHosts) as $sessionHost) {
+ if (strpos($cookieDomainWithoutLeadDot, $sessionHost) > 0) {
+ $this->getCookie()->delete($this->getSessionName(), null, $sessionHost);
}
}
}
@azurams
Copy link

azurams commented Apr 8, 2016

Hi,
what is the cookie configuration to use with this patch ?
I have http://store.dev (cookie domain: .store.dev) and http://sub.store.dev (cookie domain: .sub.store.dev) with this patch on Magento 1.8.1.0, and i'm still unable to login on sub.store.dev if main store.dev cookie exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment