- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would like to display the user's name if logged in or a link to login if not on a php page outside of Magento. They are all within the same domain. I'm using CE2.2.
Thanks,
Mike
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @MIKE_JF,
You can't access logged customer info outside the magento folder. It is against the magento security standards.
If you want to create a simple php file inside the magento root folder then you can access by following way.
<?php ini_set('display_errors', 1); error_reporting(E_ALL); use Magento\Framework\App\Bootstrap; require 'app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $state = $objectManager->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); $customerSession = $objectManager->create('Magento\Customer\Model\Session'); if($customerSession->isLoggedIn()) { echo $customerSession->getCustomer()->getName(); }
I hope it will help you!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Check to see if user is logged in on external php page
On which page you want to show customer name outside of magento.
Is it php page or html or any else? Then I can suggest you better solution.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Check to see if user is logged in on external php page
Hi Vimal,
It is a php page in the root folder of the website. The Magento installation resides in the /store sub directory.
Thanks,
Mike
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @MIKE_JF,
You can't access logged customer info outside the magento folder. It is against the magento security standards.
If you want to create a simple php file inside the magento root folder then you can access by following way.
<?php ini_set('display_errors', 1); error_reporting(E_ALL); use Magento\Framework\App\Bootstrap; require 'app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $state = $objectManager->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); $customerSession = $objectManager->create('Magento\Customer\Model\Session'); if($customerSession->isLoggedIn()) { echo $customerSession->getCustomer()->getName(); }
I hope it will help you!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Check to see if user is logged in on external php page
Thank you!