2

I know that the following code detects login for a user:

if(!Mage::getSingleton('customer/session')->isLoggedIn()){
    //not logged in
}else{
    // logged in
}

However, what is the corresponding code to determine if a user is logged in as admin?

Also, what class and method would you use to redirect to admin login, along with a post-login redirect back to a specified page?

I'm thinking you just access a different model, however I don't know which one that is.

1

It is indeed very similar:

Mage::getSingleton('admin/session')->isLoggedIn()

But note that you cannot use this in the frontend because the frontend and adminhtml sessions are two separate sessions with different ids (you'll see that two separate cookies are stored), so only one of them can be active at a time.

Also, what class and method would you use to redirect to admin login, along with a post-login redirect back to a specified page?

Redirect to admin login is already happening if you try to access any admin controller if you are not logged in as admin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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