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

error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
$app = Mage::app('default'); 
 require '/app/bootstrap.php';
    $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
    /** @var \Magento\Framework\App\Http $app */
    //$app = $bootstrap->createApplication('DemoApplication');

 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
 $state = $objectManager->get('Magento\Framework\App\State');
//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();

  • I want that session in WordPress which is placed in magento root directory. I have created one file in theme front-page.php just want to know how it works. that page is working. could you please let me know how to set path for bootstarp – Gagan Nov 8 '19 at 10:55
  • I got that file but there were some error Warning: constant(): Couldn't find constant ParagonIE_Sodium_Compat::BASE64_VARIANT_ORIGINAL php72compat.php on line 91 – Gagan Nov 8 '19 at 11:10
  • @Gagan: Regarding front-page.php : Yes, You can add this code inside <?php ?> PHP tag then check in browser like: yourdomain.com/front-page.php – Sangeeta Chandaliya Nov 8 '19 at 11:21
  • 1
    Thanks @sangeeta its working fine but with some alterations. I will update that code on monday thanks for help😊😊 – Gagan Nov 8 '19 at 17:26
  • you can check your code now sangeeta thanks again – Gagan Nov 11 '19 at 13:47

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.