require_once 'mystore/app/Mage.php';
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
$user = Mage::getModel('admin/user')->loadByUsername('admin');
if (Mage::getSingleton('adminhtml/url')->useSecretKey()) {

$session = Mage::getSingleton('admin/session');

if ($session->isLoggedIn()) {
  echo "Logged in";
  $redirectUrl = Mage::getSingleton('adminhtml/url')->getUrl(Mage::getModel('admin/user')->getStartupPageUrl(), array('_current' => false));
  header('Location: ' . $redirectUrl);

It is redirecting to the admin panel but shows the login page. Is it possible show the dashboard as the admin is already logged in?

1 Answer 1


I will not get into how much of a security hole this code would expose. I am sure that you know what you are doing.

First of all, you are loading up the "default" store. You should be loading the "admin" store Mage::app(0) or Mage::app('admin').

I don't understand what you are doing with line 4 of your code... you should probably just use:

$session = Mage::getSingleton('admin/session');

// don't mess with the existing admin session
if ($session->isLoggedIn()) {

    // redirect has to go somewhere... 
} else {
    // continue on with login code here

The Magento Admin login code is handled in:

  • I installed manthan extension for multi vendor store.I am trying to login to the vendor panel from the frontend.Your suggestion returns the same result as it is not redirecting to the dashboard and stays in the login page.Do you have any suggestion?
    – Rose
    Commented Dec 13, 2016 at 6:04
  • The example code was not complete, and I am not familiar with the manthan extension.
    – Phil M
    Commented Dec 13, 2016 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.