0

I have a magento installation I want to access the logged in admin credentials in a file inside a subfolder. I make a file and keep it in the root (the same folder where the magento index.php resides). It shows me the logged in user data perfectly. Now when I copy the same file inside a subfolder it returns the data but the data array(which contains the loggedin user information) is empty. Below is the code

require_once ('app/Mage.php');

Mage::app();

$user = Mage::getSingleton('admin/session');

print_r($user);

0

The proper way to get the current logged in admin user in a sub folder is as below.

require_once ('../app/Mage.php');
$admin = Mage::getSingleton('admin/session')->getUser();

As the custom file is in a sub folder at the root of the magento, so you have to include Mage.php properly as mentioned in above code.

Now you can fetch different admin properties as below:

$admin->getId(); //Get ID
$admin->getUserName() //Get user name

Hope this helps.

Thank you

  • The same issue the code you provided works in the file that is in the root. But inside php file in the folder when I paste this it says Call to a member function getId() on a non-object – AbdulBasit May 31 '16 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.