Magento: How to Login to magento admin externally or programmatically.
There may be some case, Where we need to login to magento admin externally and make some updates without login to the magento admin panel.
save the below code in a file and make sure that the path for Mage.php is correct depending on the location of the file you created.
<?php
require_once 'app/Mage.php';
umask(0);
$app = Mage::app('default');
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
// supply username
$user = Mage::getModel('admin/user')->loadByUsername('admin'); // user your admin username
if (Mage::getSingleton('adminhtml/url')->useSecretKey()) {
Mage::getSingleton('adminhtml/url')->renewSecretUrls();
}
$session = Mage::getSingleton('admin/session');
$session->setIsFirstVisit(true);
$session->setUser($user);
$session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());
Mage::dispatchEvent('admin_session_user_login_success',array('user'=>$user));
if ($session->isLoggedIn()) {
echo "Logged in";
}
else{
echo 'Not Logged';
}
There may be some case, Where we need to login to magento admin externally and make some updates without login to the magento admin panel.
save the below code in a file and make sure that the path for Mage.php is correct depending on the location of the file you created.
<?php
require_once 'app/Mage.php';
umask(0);
$app = Mage::app('default');
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
// supply username
$user = Mage::getModel('admin/user')->loadByUsername('admin'); // user your admin username
if (Mage::getSingleton('adminhtml/url')->useSecretKey()) {
Mage::getSingleton('adminhtml/url')->renewSecretUrls();
}
$session = Mage::getSingleton('admin/session');
$session->setIsFirstVisit(true);
$session->setUser($user);
$session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());
Mage::dispatchEvent('admin_session_user_login_success',array('user'=>$user));
if ($session->isLoggedIn()) {
echo "Logged in";
}
else{
echo 'Not Logged';
}
Thank you very much Dinesh. This snippet helped me.
ReplyDeleteI have implemented in code in my wordpress site and it displays the message as logged in as well. But when i visit magento admin page, it still displays login screen. Please help.
ReplyDeleteHey this looks familiar, source/credit goes a long way. https://stackoverflow.com/questions/4973134/magento-admin-login-through-curl
ReplyDeleteIt's not working if SID is off in admin configuration. Do you have any other idea about that ?
ReplyDelete