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';
}