Question

I want to know if it is possible to get customer session data outside of magento2

<?php
error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
$app = Mage::app('default'); 
Mage::app();
?>
Was it helpful?

Solution

 require '/app/bootstrap.php';
    $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
    /** @var \Magento\Framework\App\Http $app */
    //$app = $bootstrap->createApplication('DemoApplication');
    //$bootstrap->run($app);

 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
 $state = $objectManager->get('Magento\Framework\App\State');
 $state->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL);
//mysql connection
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of object manager
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();

$customerSession = $objectManager->get('Magento\Customer\Model\Session');

if($customerSession->isLoggedIn()) {
   echo $emial =    $customerSession->getCustomer()->getEmail();

}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top