Can we login+logout Magento admin by simple PHP code which presents outside Magento setup. I need this functionality because my requirement only full fills by this scenario only.
mywebsite.com/magentosetup (Magento setup here)
mywebsite.com/hitme.php (I need a custom script here for login and logout)
How can I do this with PHP+magento code customization?
For logout, I find this example link but this code does not work for me.
I checked the code in Indexcontroller of Magento for logout function here only these lines are present.
$adminSession = Mage::getSingleton('admin/session');
$adminSession->unsetAll();
$adminSession->getCookie()->delete($adminSession->getSessionName());
$adminSession->addSuccess(Mage::helper('adminhtml')->__('You have logged out.'));
$this->_redirect('*');
But this line of code is not working externally for logout externally. When echo this line in Magento section
$adminSession->getSessionName()
it provides "adminhtml" but the same line externally PHP file it provides "PHPSESSID". Let me know what can I do for login and logout admin programmatically.
Best Answer
Below is code that worked on my EE dev box to log you out of the admin:
I tested this code and it worked on my EE dev box, but I lifted it from this answer: Programatically login admin into admin panel possible or not
Be sure to set "yourusername" to the username of the user you wish to log in.