Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Check for Admin login on frontend
 
timpea
Member
 
Total Posts:  68
Joined:  2007-09-03
 

Hey,

I am wanting to alter the SagePay payment module so that if I am logged in to the Admin, then the frontend payment will take a MOTO (Mail Order/Telephone Order) payment, rather than the normal Ecommerce payment.  I can easily change the plugin to take a MOTO payment, but I am really struggling to check if I am logged into the Admin from a module in the frontend.

I can use this code in a file that is outside of the magento code to detect:

require_once('app/Mage.php');
Mage::app('default');
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
$session Mage::getSingleton('admin/session');

if ( 
$session->isLoggedIn() ) {
    
echo "logged in";
else {
    
echo "not logged in";
}

But as soon as I use this code within the frontend it doesn’t work.

Does anyone have any idea how to do this without me using curl in php to get the output of my external file.  It seams like such a simple thing to do.

Cheers
Tim

 
Magento Community Magento Community
Magento Community
Magento Community
 
timpea
Member
 
Total Posts:  68
Joined:  2007-09-03
 

Is there anyway of creating a new instance of Mage::app()?  My knowledge of Object stuff isn’t good enough to figure it out.  As i assume that the only reason the code above doesn’t work in the frontend is because the Mage object is already loaded with the frontend stuff, and some security measures stops the frontend using admin functions.

 
Magento Community Magento Community
Magento Community
Magento Community
 
zachc
Jr. Member
 
Total Posts:  6
Joined:  2010-11-21
 

Hey I’m running into a similar problem too - I writing an extension and need to access the admin user’s email address and name in my extensions setup script.

I’ve also tried $session = Mage::getSingleton(’admin/session’); but got the same results as you.

Would appreciate some help if you have figured it out. Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
youngilaboungi
Jr. Member
 
Avatar
Total Posts:  28
Joined:  2008-11-27
Alexandria, Egypt
 

you were actually checking if the user has logged in to admin area, not if an admin user is logged in.
I would look in admin/user model, see if there is a table entry that says this user is logged in, or at least if the admin user has a session setup.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mkk_kashif
Jr. Member
 
Total Posts:  25
Joined:  2010-12-22
 

It is quite simple but not a recommended solution. I myself spend number of hours to do this.
For, windows based server try below solution:

$sessionFilePath Mage::getBaseDir('session').DS.'sess_'.$_COOKIE['adminhtml'];
    
$sessionFile     file_get_contents($sessionFilePath)
    
$exp_cookie      explode(';',$sessionFile);
    if(
count($exp_cookie)    >    100)
    
{
      
return "login";
    
}
    
return "expire";

For, Linux based server try below solution:

$sessionFilePath Mage::getBaseDir('session').DS.'sess_'.$_COOKIE['adminhtml'];
    
$sessionFile     file_get_contents($sessionFilePath)
    
$exp_cookie      explode('--',$sessionFile)
    if(
count($exp_cookie)    >    10)
    
{
      
return "login";
    
}
    
return "expire";

Thanks,
Kashif

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top