Can't Login to Magento Admin Panel after successful Installation

Here's a simple solution to those facing Fresh Magento Installation Backend login problem. It's obviously an issue around Cookie settings. So let's get to it.




First thing you got to do is look for a file named Varien.php which is located same way as the following.

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

In my case, magento_url represents 'c:\wamp\www\magento'.

Using your text-editor, open the said file. Look for the code around line 78 that reads 'session_set_cookie_params(...);'. Then enclose the entire code block inside a multi-line Comment (/* ... */).

It should look something like the following.

// set session cookie params
/*
session_set_cookie_params(
    $this->getCookie()->getLifetime(),
    $this->getCookie()->getPath()
    $this->getCookie()->getDomain(),
    $this->getCookie()->isSecure(),
    $this->getCookie()->getHttponly()
);
*/

Well there you have it. This is the shortest workaround I've found in Magento Forums. Once you get this working, you'll never have to replace http://localhost/ into http://127.0.0.1/ ever again. If you're not convinced, try running another fresh installation of Magento. Fix Varien.php, then access the backend or admin section. You'll be surprised the problem's gone!

This piece of solution is offered for development purposes only. This might not be a good idea for a production environment. Please bear that in mind.

Here's my Platform specs to give you some hint:
  • OS: Vista
  • Server: WAMPServer
  • Browser: Firefox 3+, IE7, Safari 3+


Related Posts:


Bookmark and Share

37 comments :

Anonymous said...

Thanks for the tip!
I have been struggling with this for a couple of hours, before findind your tip.

Ben said...

you're a genius.. why do such simple problems even exist... it must be very common

shuvo said...

Thanks for tips.Its working

Anonymous said...

cool, thanks for the fix.

Anonymous said...

I have tried the same thing, I am using Vista, Winamp and have successfully installed a wordpress site for production testing. The front end is working perfectly, but I cannot access the admin. It keeps saying password / username incorrect. I have gone into php MyAdmin to make sure the password is the same under the admin table & it is... help! Have changed the localhost to 127.0.0.1 & still no luck, have commented out above... What am I doing wrong??

bassgrinder said...

Try installing another copy of Magento with the above changes and see if the result's still the same. If so, then we need to check for some other factors which might have caused this. You can mail me if you want. Here's my address: bassgrinder at g mail.

Anonymous said...

you are really genioussssssssss

Anonymous said...

Thanks a lottttt.....your post helped me to solve a huge problem....

Zahir Khan said...

hi. I tried this but when I try to login I get the error Invalid Username or password. The login details I am using are correct. Do u knw any work around for this?

Anonymous said...

apache server,ssh:
hey i got mysqp5.0 n php5.2...all d other reqd are fulfiled..still itz showing an error of:you need MySQL 4.1.20 (or greater)..plz help me...

Nanhe Kumar said...

your answer is really good thanks
this solution is not any where

Anonymous said...

I have just installed Magento v 1.4.0.1 on WAMP and need to be able to log in. The file Varian.php seems to have changed from lines 77 on. I managed to get it to work by commenting the whole block lines 77-104:

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

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();
}

call_user_func_array('session_set_cookie_params', $cookieParams);

if (!empty($sessionName)) {
$this->setSessionName($sessionName);
} */

Hope you will update this advice.

Abdul Ghafoor said...

Hi,
I'm having similar problem due to increase of disk space on my server. It was gone above 100%. By reducing disk space to under 100%, solved my problem.

Gravata said...

In fact, in version 1.4.0.1 you can comment only the line #100 ( call_user_func_array('session_set_cookie_params', $cookieParams); ) and it will work

J Feels said...

Wow!!

This made it work:

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

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();
}

call_user_func_array('session_set_cookie_params', $cookieParams);

if (!empty($sessionName)) {
$this->setSessionName($sessionName);
} */

Richard Feraro said...

Instead commenting all those line of codes which make it pretty unsecured when used in a production environment, why not detect the domain if its localhost and disable it and restore usual function when it's not.

This is how I did it:
http://mysillypointofview.wordpress.com/2010/03/24/how-to-fix-magentos-admin-login-failing-no-error-message-on-localhost/

Anonymous said...

I have tried all of those, none worked... :S

Nathan Chick said...

Thanks for this, I was scratching my head for a little while :)

Anonymous said...

Nothing of that works on the mac with MAMP using Firefox. No problem using Opera or Safari. I would like a solution because Firefox has a tool called firebug that I like to use.

Anonymous said...

@Gravata: Thanks!

Anonymous said...

Hi there,

I am using this simple procedure under Windows7:
1. install XAMPP and enable "iconv"

2. edit the file "hosts" to this: 127.0.0.1 localhost.com

3. copy the magento files to the directory: C:\xampp\htdcs\magento\

4. start the Apache and MySQL

5. Go to the address: http://localhost.com/magento

6. Follow the installation wizard.

7. Now You will be able login to the administration.

ENJOY!

=D

Anonymous said...

thnx dude!

Anonymous said...

good post keep up dear same help

magento developer said...

Thanks for sharing this information. It was really informative and helpful as well.

lala said...

Thanks for your post and welcome to check: here
.

search engine optimization melbourne said...

Aw, this was a really quality post. In theory I'd like to write like this too - taking time and real effort to make a good article... but what can I say... I procrastinate alot and never seem to get something done.

Anonymous said...

None of the above works in 1.5 version even after emptying the cache. Any Help?

magento theme said...

I like the writing structure of your blog and it does a pretty decent job of presenting the material. Thanks for sharing!Magento Themes

pcf said...

What if your on a shared host?

Magento Modules said...

I am trying it on 1.6, but not working.

Magento Product Reviews said...

Hey thanks for sharing this. I have been struggled with the issue for a long time and nobody turned out with a result. Thanks once again.

Anonymous said...

thanks , its working fine on magento 1.8 edition

Ashish Khadpe said...

I am still confuse on how to implement this for my magento development company website : Parsys Media

Andie said...

Great read! I will come back for more :)

Florida Magento Developer

Barney Erikson said...

A very good and informative article indeed. It helps me a lot to enhance my knowledge.
professional web design utah

Andie said...

Great article! I think this article will support and complement your point
Florida Web Development

Zinavo Bangalore said...

These provided information was really so nice,thanks for giving that post and the more skills to develop after refer that post. Your articles really impressed for me,because of all information so nice.Web Design Company | Website Development Company Bangalore

Post a Comment

Hi there! Please leave your message here. Also, I may not be able to respond to your query right away. So please bear with me. Thanks. :)