Magento 1.9 Can’t login to admin panel!

I have installed Magento 1.9. It was working well for a week. Suddenly yesterday, when I tried to log in to the Magento admin panel and I typed username and password, clicked the Login button and nothing happened. The page refreshes and that’s all. No error or any other messages.

If I entered the wrong username or password, It shows an error.

After I googled about this issue, I was recommended to comment the following lines in:

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

/* to solve login issue */
  /*if (!$cookieParams['httponly']) {
  unset($cookieParams['httponly']);
  if (!$cookieParams['secure']) {
  unset($cookieParams['secure']);
  if (!$cookieParams['domain']) {
  unset($cookieParams['domain']);
  }
  }
  }
   
if (isset($cookieParams['domain'])) {
  $cookieParams['domain'] = $cookie->getDomain();*/ //I have commented these lines

And for some older versions below was recommended in the same file.

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

Even after that, I could not log in to admin. It is as it was. Did anyone face this issue? Is there any other solution to this issue?

(I tried clearing cache and session through FTP).

Solutions

I'm having the same symptoms on some Magento installations(not only 1.9). In my case, it happens only in Chrome. I'm fixing this by logging in Firefox/Safari/Opera, and changing 'Use HTTP only' to 'No' in 'Session Cookies Management' of the 'Web' settings.

See Magento's backend screenshot with cookies settings

While it may offer you a temporarily solution, you should considering not modifying the core code like that to solve problems. Changing the source code of an application will create problems that are much more difficult to track down.

There's a number of different issues that cause the errorless admin login behavior you're seeing, but they all go back to Magento not being able to set or read the session cookie. Magento uses sessions to pass error messages between pages — that's why you don't see an error message. Magento also uses sessions to store the "is logged in" value, so not setting sessions also causes the core error behavior.

Possible causes include

  • Local computer time vs. server time mismatch, causing instant cookie invalidation. Make sure your server time is correct.

  • Incorrect permissions on var/session, preventing session files from being saved

  • Incorrect configuration of database/redis/other session storage, preventing saving of session values

  • A module is instantiating sessions to early, preventing the correct session names from being set

  • You're a developer using multiple URLs and have multiple cookie domains

  • Another developer has somehow modified app\code\core\Mage\Core\Model\Session\Abstract\Varien.php, creating a hard to track down bug

  • The cookie domain in System -> Configuration -> Web -> Session Cookie Management doesn't match the actual site domain.

  • You're using the localhost as your server domain, and using a version of webkit that has trouble/bugs setting cookies for localhost in some situations.

The short term fix is to just delete your cookie for the domain. That's often enough to solve the problem. If it persists, figure out which of the above reasons is the reason for your error, and take steps to address it (fix permissions, etc.)

I had this problem too. Turned out sessions couldn't get written to var/session, even though the directory itself is set to 0777. Magento created session files, but they all remained zero bytes.

Changing session storage from files to db solved the problem for me.

Similar questions

Can't Login Admin Panel, Return's Blank Page
I've moved my project from local to live but I can't login to my admin panel, it's returning a blank page I've tried giving permission to var/session var/cache(and cleared them) media folders etc. but still the problem persist. But the frontend is working fine...
I can't login to admin panel
may i have some assistance , I can't login to admin panel and the notification is as follows : There has been an error processing your request Exception printing is disabled by default for security reasons. Error log record number: 155187663629 may i have some solution please
Magento admin login and admin panel are extremely slow
I have problem with speed of magento admin panel, login in backend and other sections of admin panel are very extremely slow. I did all items in below links but speed did not change:
Magento admin dashboard is not showing after login to admin panel
I have installed fresh Magento2.1 EE version. After login to my admin panel, the dashboard shows the error I have also attached the screenshot of the same
Programatically login admin into admin panel possible or not
I am working on the script for the login of admin panel automatically into the admin panel. Here is code link which is used for automatically login admin user into the admin panel. But it is not working when I run simple code then it says authenticated but it is not login into admin area when I open admin then it lands to login page only. I also go...
"Invalid Form Key. Please refresh the page" on Admin login page. I set the wrong cookie domain in the Admin panel. How to change that in the database?
I am setting up a new Magento 1.9.4 store but I am setting that up for an existing live store which is currently running Magento 1.9.1. I made the mistake of entering the other domain into the cookie domain setting in the Admin panel and it won't let me login into the Admin panel. I get the following Error: I deleted browser and Magento Cache (via ...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.