How to Fix Magento’s Admin Login Failing (no error message) on Localhost

You want to install a new Magento instance (version 1.4.0.1 at the time of this writing) in your machine. You followed every steps from downloading up to the setting up of your admin account. Everything went fine so you assumed you’re good to go. You tried to login using your admin account… nothing happened. You tried again… Same login screen with no error whatsoever. You wonder what went wrong. You checked the files and the database as well as clearing the cache. You even tried resetting your account’s password found in the Magento’s admin_usertable using the MD5 function thru phpMyAdmin but to no avail. You gave up and tried to reinstall everything only to be greeted by the very same login screen after clicking the Login button.

The real problem lies when a Magento instance is running through a localhost and tries to create a cookie, but fails to do so because it requires a domain and localhost is not a true domain (thanks to Mohammad Abdul Momin Arju for pointing this out in his blog). You can do a simple check to validate this by using Firefox and Firebug to check if a cookie is being generated by the Magento’s Admin Panel login page.

Magento's Admin Panel Login without cookie being generated upon loading

Magento's Admin Panel Login without a cookie being generated upon loading

At this point, we have to edit the core files without breaking the functionality behind this domain checking feature of Magento. To do this, open the following file:

Copy the Varien.php core file which can be found below:

app\code\core\Mage\Core\Model\Session\Abstract\Varien.php

where we assumed that your root directory is htdocs and inside it is yourmagento folder.

Paste it in the Magento ‘local’ folder which can be found below (create needed folders if it doesn’t exists) and open the file for editing:

app\code\local\Mage\Core\Model\Session\Abstract\Varien.php

Go to line 96 or locate the code similar below:

if (isset($cookieParams['domain'])) {
    $cookieParams['domain'] = $cookie->getDomain();
}

Replace the code found in line 96 with this one:

if (isset($cookieParams['domain']) && !in_array("127.0.0.1", self::getValidatorData())) {

For Apple machines or other operating system, try what Nirav did found in hiscomment.

The purpose of this code change is to disable the Magento’s domain checking only if it is accessed via localhost and run as usual if it is being accessed thru a valid domain.

Clear your browser’s cookies to start with a clean slate then clear the Magento cache by deleting all the contents of the following folder:

var\cache

Access the Magento Admin Panel login again thru localhost while your firebug’s cookie tab being on (http://localhost:8080/magento/index.php/admin/). It should display something similar to the image below indicating that a cookie with an adminhtml name has been generated.

Magento's Admin Panel Login with a cookie being generated upon loading

Magento's Admin Panel Login showing a cookie 'adminhtml' generated after loading

At this point you should be able to login now with your admin username and password using localhost as your domain.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值