0

I am trying to figure out what is going wrong in my Magento 1.8.1 setup.

My Magento 1.8.1 installation is all working fine if I access it from the server IP (e.g. XXX.XXX.XXX.XXX/magento).

After I configured my domain (e.g. xxx.xxxxx.com), the index.php page and the index.php/admin seem to load ok. However I am not able to login in both of them using Chrome.

Actually I was able to login the first time, then after I logged out I am not able to login anymore. Even clearing cookies on the browser and emptying the var/session and var cache folder seems to change nothing (I am only able to login the first time).

I also tried to comment out some lines (87-104) on the Mage\Core\Model\Session\Abstract\Varien.php file, nothing changed (it only created a long list of warning in my system.log).

    // session cookie params
    // $cookieParams = array(
    //     'lifetime' => $cookie->getLifetime(),
    //     'path'     => $cookie->getPath(),
    //     'domain'   => $cookie->getConfigDomain(),
    //     'secure'   => $cookie->isSecure(),
    //     'httponly' => $cookie->getHttponly()
    // );

This problem seems related to Chrome, in Internet Explorer and Safari it seems to work fine. In Chrome with Incognito mode all seems to work fine sometimes (sometimes it works also after loggin out, sometimes after loggin out I am not able to login again as without the incognito mode).

  • Please try it in incognito mode once? – Sukumar Gorai Jun 4 '18 at 8:24
  • Actually it works in incognito mode... – Niko Zarzani Jun 4 '18 at 8:28
  • clear the cache and cookies of chrome browser and try – Rahul Singh Jun 4 '18 at 9:09
  • after I clear the cache I am only able to login once, if I log out and login again it gets stuck at the login page... – Niko Zarzani Jun 4 '18 at 9:17
0

I noticed that clearing the cookies manually, refreshing the login page and the perform again the login was effectively a manual workaround.

I decided to write a simple script that can be put in the login page in order to empty the magento cookies stored by chrome each time a user visits the login page.

Here it follows the workaround script

<script type="text/javascript">
  function deleteAllCookies() {
    (function () {
        var cookies = document.cookie.split("; ");
        for (var c = 0; c < cookies.length; c++) {
            var d = window.location.hostname.split(".");
            while (d.length > 0) {
                var cookieBase = encodeURIComponent(cookies[c].split(";")[0].split("=")[0]) + '=; expires=Thu, 01-Jan-1970 00:00:01 GMT; domain=' + d.join('.') + ' ;path=';
                var p = location.pathname.split('/');
                document.cookie = cookieBase + '/';
                while (p.length > 0) {
                    document.cookie = cookieBase + p.join('/');
                    p.pop();
                };
                d.shift();
            }
        }
    })();
  }
  function setCookie(name,value,days) {
      var expires = "";
      if (days) {
          var date = new Date();
          date.setTime(date.getTime() + (days*24*60*60*1000));
          expires = "; expires=" + date.toUTCString();
      }
      document.cookie = name + "=" + (value || "")  + expires + "; path=/";
  }
  function getCookie(name) {
      var nameEQ = name + "=";
      var ca = document.cookie.split(';');
      for(var i=0;i < ca.length;i++) {
          var c = ca[i];
          while (c.charAt(0)==' ') c = c.substring(1,c.length);
          if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
      }
      return null;
  }

  var isChrome = !!window.chrome;
  if(isChrome){
    var shouldResetCookies = getCookie("shouldResetCookies");
    if(shouldResetCookies == null || shouldResetCookies == "true"){
      deleteAllCookies();
      setCookie("shouldResetCookies", "false", 1);
      shouldResetCookies = getCookie("shouldResetCookies");
    }
    else if(shouldResetCookies == "false"){
      setCookie("shouldResetCookies", "true", 1);
      shouldResetCookies = getCookie("shouldResetCookies");
      location.reload();
    }
  }

</script>

I hope it will be helpful to someone with my very same problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.