Sunday, April 19, 2009

After installing magento can't log in to admin panel

Problem Description
While installing magento on xampp version 2.5 you have provided admin username and password. After installation finished you no longer login with your admin account. In fact in the "Log in to Admin Panel" window whenever you provide wrong password/username combination it displays "Invalid Username or Password." But whenever you provide correct password it does not show anything. Though a new url like
http://127.0.0.1/magento/index.php/admin/index/index/key/d135be4de664ab83db829120740e058a/

is displayed on the address bar.
Everytime you do this you can't log in to admin panel.

Cause of the problem
The problem occurs because magneto could not store cookies. We run it as localhost and localhost is not true domain but to store cookies we need a domain. That's why login stops without saying any word.

Solution of the problem
Way 1:
In different forums I saw they mentioned connecting as http://localhost/magento/index.php/admin will fail but if you connect as http://127.0.0.1/magento/index.php/admin it will work. But in my case IP address in the URL did not work too.
I made it work into whenever I changed my browser. Suppose I installed magento using google chrome browser and I open admin url into my firefox window and it worked. Though in the firefox the url http://localhost/magento/index.php/admin did not work, but url http://127.0.0.1/magento/index.php/admin worked fine.

Way 2:
-Go to app/code/core/Mage/Core/Model/Session/Abstract/Varien.php file within your magento directory.

-Find the code,

session_set_cookie_params(
$this->getCookie()->getLifetime(),
$this->getCookie()->getPath(),
$this->getCookie()->getDomain(),
$this->getCookie()->isSecure(),
$this->getCookie()->getHttponly()
);

-Replace above code by,

session_set_cookie_params(
$this->getCookie()->getLifetime(),
$this->getCookie()->getPath()
//$this->getCookie()->getDomain(),
//$this->getCookie()->isSecure(),
//$this->getCookie()->getHttponly()
);

-Save it and try to login to your magento admin panel.
It would work. :)

Related Documents
http://arjudba.blogspot.com/2009/04/magneto-installation-crashes-apache.html

18 comments:

  1. Thank you Very much, for the information.

    ReplyDelete
  2. Awesome. After a long search at last I found this a workable solution.
    Thank you.

    ReplyDelete
  3. Its a simple but great work around. Thanks for the information. I have not gone into the code deep yet... so i have a concern. Will it expose any unforseen security loop hole into the system?

    ReplyDelete
  4. Useful post, thank you.

    ReplyDelete
  5. I had the same problem.
    Changing the path in my browser from http://localhost to http://127.0.0.1
    got me to log in.
    Anybody an idea why this might happen?

    ReplyDelete
  6. Thank you very much! I tried to clear my cookies and accept cookies, but no results. Whit this great tutorial I solved my problem. Thank you very much!

    ReplyDelete
  7. Thank you very much! This FINALLY fixed my problem after about 5 hours of frustration trying everything else and it wasn't working. Can't thank you enough.

    ReplyDelete
  8. You sure are a lot of help! Thank You!

    ReplyDelete
  9. This solution works fine...but is it a secure way to do this change...

    ReplyDelete
  10. I used second way - it works.
    Thank you!

    ReplyDelete
  11. thank you very much:-)

    ReplyDelete
  12. it doesn't work neither the way 1 nor the way 2

    ReplyDelete
  13. it doesn't work I continue to have the same problem

    ReplyDelete
  14. I tried to search that kind of code in my file located at - magento\app\code\core\Mage\Core\Model\Session\Abstract\Varien.php

    but i find that my code in my file is something different that i found on in posts in various forms.

    Mine is like this way -

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

    any one please tell me why mine is different than others and what kind of changes i can do to get the admin working.

    Many thanks in advance

    ReplyDelete
  15. try changing your servername in your vhosts file as well as your hosts file. add a dot something to the end.

    sample hosts file entry:
    127.0.0.1 magento.local

    sample vhosts entry:

    ServerName magento.local
    ...


    with this you shouldn't need to preload the sample db.

    ReplyDelete
  16. I commented out these in 1.4.x:

    //'domain' => $cookie->getConfigDomain(),
    //'secure' => $cookie->isSecure(),
    //'httponly' => $cookie->getHttponly()

    ReplyDelete
  17. Thank you..........

    ReplyDelete