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.
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!
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
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!
Thank you!