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

[SOLVED] How can I retrieve the admin user session from outside Magento? 
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

Hi guys, I’m trying to retrieve the logged in admin user info from a non Magento page. How would I go about doing this?

The following returns NULL

require_once '../app/Mage.php';

Mage::app();

Zend_Debug::dump(Mage::getSingleton('admin/session')->getUser());

Thanks,

LL

 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

Hi guys,

After searching the forums extensively, I have been unable to find an answer to my problem. I have, however, found several other people with the same problem. Their posts did not receive a reply either. No idea why. Surely someone know how to do this… right?

Please and thank you,

LL

 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

Hi guys,

Another bump because this thread still has 0 views (I guess I have to get more creative with my thread titles). In any case, I am really stuck on this and could really use some help.

Your help is most appreciated,

LL

 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

Uhhh, hello?… *crickets*

 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

4th bump in 6 days, and still this thread has 0 views?

Could really use some help here… anyone?

 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

another bump… this is rather a sad support forum. :(

 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

*bump*…

 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

*bump* ...

 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

*bump* . . .

 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

*bump* . . .

 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

*bump* .  .  .

 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

*bump*… Lets see if I have better luck getting a reply this week.

 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

Uh, what does a guy need to do to get a reply around here?

 
Magento Community Magento Community
Magento Community
Magento Community
 
QuickModules
Jr. Member
 
Total Posts:  29
Joined:  2009-05-28
 

Here is your solution:

require_once('app/Mage.php');

// Initialize Magento
Mage::app();

// This initalizes the session, using 'adminhtml' as the session name.
// Just ignore the returned Mage_Core_Model_Session instance
Mage::getSingleton('core/session', array('name' => 'adminhtml'));

// Get a singleton instance of the Mage_Admin_Model_Session class
// This is just the 'admin' namespace of the current session. (adminhtml in this case)
$session Mage::getSingleton('admin/session');

// Use the 'admin/session' object to check loggedIn status
if ( $session->isLoggedIn() ) {
    
echo "logged in";
else {
    
echo "not logged in";
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

QuickModules, that was most appreciated. Thank you!

Peace be upon you…

LL

 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

QuickModules, when i first tried your code it was working. However, now that I’m looking at this again, it’s returning bool(false) again, whether I’m logged in as an admin or not.

I found this suggestion in the following thread as well, however, none of the suggestions in there worked for me:
http://www.magentocommerce.com/boards/viewthread/17274/

Edit:

Found the problem. The problem had to do with the code of third party application I was integrating.

Thanks!

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