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);

asked May 31, 2016 at 10:36

1 Answer 1

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

answered May 31, 2016 at 10:42
1
  • 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 Commented May 31, 2016 at 10:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.