Home > blog posting, magento, technical notes > Magento Notes - Fix for admin login problem

Magento Notes - Fix for admin login problem

February 9th, 2009

Today’s Magento installation has become a real drag!! The upgrade to version 1.2.1 was troubling as after the upgrade I had trouble logging into the admin page.  After digging for hours trying to find a fix, I finally came up with the right fix!! View Entire Thread Here

The long and short of the fix is that apparently the newer Magento version is implementing some security check to make sure that the domain is a valid one that is accessing the admin page; a valid domain name or host consists of one with a period in the host name, so if you are installing locally using something like http://localhost, YOU WILL RUN INTO THIS PROBLEM! There are a couple ways to fix this

1) you can reference your admin page by using http://127.0.0.1 (this way it has periods in the host name) instead of localhost or

2) if you are on windows xp, add a host record in your hosts file by going to: C:\WINDOWS\system32\drivers\etc and have 127.0.0.1 point to something like magento.localhost

3. modify the core Magento code (keep in mind you may have to re-apply the fix if you update the code Magento code) - go to: app/code/core/Mage/Core/Model/Session/Abstract and open up varien.php, and comment out lines 73 (comment out the comma at the end of the line) through 76 so that it looks like the following:

// set session cookie params
session_set_cookie_params(
$this->getCookie()->getLifetime(),
$this->getCookie()->getPath() //remove this after putting on server (leave the comma)   ,
//$this->getCookie()->getDomain(),
//$this->getCookie()->isSecure(),
//$this->getCookie()->getHttponly()

);

I am sure many people will appreciate this fix!

Bookmark and Share


blog posting, magento, technical notes ,

  1. pawan
    March 4th, 2009 at 00:06 | #1

    hi thank you friend its realy helpfull for me :)

  2. March 5th, 2009 at 10:26 | #2

    Thanks. Works perfect (You can change a domain - with dots - it works too).

    Regards.

  3. March 5th, 2009 at 10:59 | #3

    Glad it works.

  4. Andrea
    March 9th, 2009 at 08:04 | #4

    Thank you very much!!! You have help me so much! Thanks Thanks Thanks

  5. March 9th, 2009 at 08:16 | #5

    My pleasure :-)

    Would love to see your Magento site when you have it running. Good luck.

  6. Plotz
    March 16th, 2009 at 08:57 | #6

    Does not solve the problem on my online installation.
    Still locked out.

    Thanks anyway.

    Another solution?

  7. March 16th, 2009 at 09:04 | #7

    Is this a local install? If so, are you able to access the admin page with the local ip of 127.0.0.1? Any error messages?

  8. March 18th, 2009 at 13:31 | #8

    Same problem on http://www.twoedgedclothing.com/ so that can’t be explained by the lack of dots in the hostname. Just installed, everything seems fine, but admin login is being denied. I reset the password to no avail.

  9. March 18th, 2009 at 14:14 | #9

    Do you get an “Access Denied” message? if you do, then it’s a totally different problem you are encountering. One way to reset the admin password is to re-setup the database config info (including admin login/pswd). You can do this by simply renaming the “local.xml” file under: /app/etc, and then re-run your web site. Good luck.

  10. wbd
    March 19th, 2009 at 22:43 | #10

    Your post (and link to discussion forum) was most helpful in de-stressing my afternoon… thank you!
    Hopefully I can get productive once again, instead of trying to trawl through web forums looking for solutions to silly problems introduced by a simple (and recommended by the developers) upgrade.

  11. March 19th, 2009 at 22:47 | #11

    Glad to know you find this helpful. Please come back and share your site with us when you launch :-)

  12. John
    March 25th, 2009 at 08:53 | #12

    Hi,
    I’ve got the same problem than Fletch (”Access Denied” when I try to log in the admin panel). I’ve tried editing the admin password or name directly in the DB, I’ve tried re-installation of the web site but nothing… Any idea?

  13. March 29th, 2009 at 23:33 | #13

    Hi Guys. I begin with my poor english. I’m sorry. Thnks so much 4 all Jerry Lee.
    So, i think i’ll learn better speak english that install or run Magento in my localhost, jiji ok anyway

    i’ve re-installed Mangeto using http://127.0.0.1/ address and that it seems to work.

    but when I enter in Admin Panel I get this message:
    Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 4864 bytes) in /var/www/app/code/core/Mage/Tag/Helper/Data.php on line 32

    Cheers people

  14. Davi
    March 30th, 2009 at 01:12 | #14

    I’ve spent half an hour to check this problem. Thank you and thanks to Google to have indexed your blog post.

  15. March 30th, 2009 at 05:36 | #15

    @Angel
    the error you have posted about memory size, I’ve never encountered, but I found this posting on Magento forum…take a look and see if it helps:

    http://www.magentocommerce.com/boards/viewthread/20534/

  16. March 30th, 2009 at 05:37 | #16

    @Davi
    You are very welcome. Come back and show us your Magento site when you are ready :-)

  17. joydeep
    April 6th, 2009 at 02:16 | #17

    Now for this reason i can’t access my site from any other machine.
    Other machine can’t recognize my machine using the magento.localhost

  18. joydeep
    April 8th, 2009 at 22:41 | #18

    Hi jerry , I am still stucking with the problem.I cant access my website
    from other machine.I think it is due to change in the host file.
    Can any body help me to solve this problem

  19. April 12th, 2009 at 08:11 | #19

    Great help!! Thank you very much

  20. April 18th, 2009 at 10:34 | #20

    You are the man… thanks bro.

  21. datashock
    April 22nd, 2009 at 20:31 | #21

    Yesssssss!!!! No works under Chrome too!!! Thank youuu!!

  22. May 5th, 2009 at 18:23 | #22

    problem solved
    using http://127.0.0.1
    thanks bro

  23. May 7th, 2009 at 13:38 | #23

    this solved my problem at localhost.
    Thanks man! :)

  24. May 17th, 2009 at 03:07 | #24

    Great Help dude!

    Thank you.

  25. May 19th, 2009 at 21:57 | #25

    there is another possible fix which works for me, edit your hosts file, linux /etc/hosts windows its somewhere else (google it) and create a domain there like magento.dev pointing to your local IP (apache) in my case 127.0.1.1 and restart apache… obviously you will need a virtual server listening on magento.dev pointing to your development site….

  26. May 19th, 2009 at 22:00 | #26

    Obviously the above is good if you have more than one development environment ^ you can change your magento base URL (temporarily) while you develop by going into phpmyadmin and running:

    SELECT * FROM `core_config_data` WHERE `path` LIKE ‘%base_url%’;

    and editing the appropriate fields….

  27. sebalois
    June 16th, 2009 at 06:53 | #27

    Thanks man!

  28. June 29th, 2009 at 22:21 | #28

    Hi,folk

    This works great!!

    Can anyone tell me What caused it to not work for localhost? I used 127.0.0.1 to access admin but it failed and then came to here and I scan all 3 solution posted on top of the page and picked third one.

    I think, if i update my magento to latest one then I would have to re-write again. Am I right?

    Thanks again

    Cheers !
    Web-Farmer@letsnurture.com

  29. vijay
    July 2nd, 2009 at 05:55 | #29

    hey thank its really done for me.
    thanks once again

  30. Niaina
    July 29th, 2009 at 00:26 | #30

    Waooooooooo,
    it’s very nice, thank you very much Sir,

  31. Varun
    August 18th, 2009 at 09:52 | #31

    awesome!!!

  32. Balasundaram.G
    August 28th, 2009 at 02:56 | #32

    Very useful post. all magento uaers must need this.

  33. fernando
    September 22nd, 2009 at 10:17 | #33

    muy bueno gracias! saludos de Peru

  34. September 23rd, 2009 at 07:38 | #34

    thanks mate! I was looking for a solution for too long. this solved the problem on my LOCAL installation!!

  35. mayK
    September 24th, 2009 at 23:52 | #35

    it doesn’t work for me on localhost. WHY??
    I tried to modify Varien.php
    I used http://127.0.0.1:8888/index.php/admin/
    and http://127.0.0.1:8888/admin/ instead of http://localhost:8888/admin
    but I can not log into the admin.

    Can anybody help PLEASE!! :(

  36. Pratik Patel
    October 10th, 2009 at 03:30 | #36

    If the domain is not a true domain then this problem occurs. Its like if you use your localhost to run magento store,then you will face this problem.

    You can overcome this by browsing using ur ip address or you can remove these three line from the following page.

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

    $this->getCookie()->getDomain(),
    $this->getCookie()->isSecure(),
    $this->getCookie()->getHttponly()

    Comment these lines line (may be at line 78…);

    Hope magento admin will work now on your localhost with the following url. :)

    http://localhost/magento/admin/

    Just try out and play with your stores……

  37. October 12th, 2009 at 03:36 | #37

    Thanks for your tips. Really its very useful for new user

  38. rajesh
    October 13th, 2009 at 05:24 | #38

    Thanks for help dude!!!

  39. October 23rd, 2009 at 03:50 | #39

    Thanks a lot bro for the help. it works for me as well…

  40. November 2nd, 2009 at 01:21 | #40

    It’s Really great tutorial.
    thanks body to help us.

    Regards
    Ramakant

  41. Allen
    November 12th, 2009 at 20:03 | #41

    thanks…the fix really helped me a lot.
    God bless.

  42. February 13th, 2010 at 01:10 | #42

    thanks, Great technique
    Adeel

  43. Biswajit
    February 18th, 2010 at 23:25 | #43

    Thanks for you help.its work fine

  44. Baseer
    February 23rd, 2010 at 23:58 | #44

    hi guys easy solution is use Opera with that its work fine. my personal experience

  45. March 10th, 2010 at 07:47 | #45

    In the latest version of which i’m using is 1.4.0.1
    in that the below mentioned code is not available

    app\code\core\Mage\Core\Model\Session\Abstract\varien.php
    $this->getCookie()->getDomain(),
    $this->getCookie()->isSecure(),
    $this->getCookie()->getHttponly()
    Comment these lines line (may be at line 78…);

    So after doing r&d i found out the solution

    search for “// session cookie params” line in app\code\core\Mage\Core\Model\Session\Abstract\varien.php

    change
    $cookieParams = array(
    ‘lifetime’ => $cookie->getLifetime(),
    ‘path’ => $cookie->getPath(),
    ‘domain’ => $cookie->getConfigDomain(),
    ‘cookieParams’ => $cookie->isSecure(),
    ‘httponly’ => $cookie->getHttponly()
    );

    to

    $cookieParams = array(
    ‘lifetime’ => $cookie->getLifetime(),
    ‘path’ => $cookie->getPath()
    );

    and comment the below mentioned code
    line number 86, in my file

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

    now login as admin, it will work

  46. April 12th, 2010 at 09:46 | #46

    Thnx, it works!!!

  47. April 29th, 2010 at 00:29 | #47

    Thanks a bunch. Its now working on my website. Hopefully, now I can learn it soon and finish up a new website design in magento.

  48. June 3rd, 2010 at 07:18 | #48

    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, then restore usual function when it’s not.

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

  1. February 22nd, 2009 at 13:17 | #1