2

In my installation of the Magento 2.2. I have a strange misbehavior related to sessions. Specifically: I can't get any data from session after the browser page has been refreshed.

As result I have an "empty" session for admin customer and I can't authorize to magento admin panel(redirect loop).

The files of the session are created(I can see them). I have been trying to use different windows server(open server) and vagrant(Homestead) and it's always the same.

The Redis has the same issue: Magento doesn't return value from the session storage.

Always prints "SET". $value is NULL:

/** @var \Magento\Catalog\Model\Session $session */
$session = $this->_objectManager->get('\Magento\Catalog\Model\Session');
$value = $session->getMyValue();
if (is_null($value)) {
     echo 'SET';
     $session->setMyValue('test');
} else {
     echo $session->getMyValue();
}
2
  • clear browser cookies and try again Nov 22, 2017 at 14:30
  • This was the first thing which I did and also, I have tried to use different browser
    – esigns
    Nov 22, 2017 at 14:40

2 Answers 2

0

You can get customer session regardless of enabling full page caching or not.

<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); ?>
<?php $context = $objectManager->get('Magento\Framework\App\Http\Context'); ?>
<?php $isLoggedIn = $context->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH); ?>
    <?php if($isLoggedIn) : ?>
        // logged-in 
    <?php else: ?>  
        // not-logged in 
    <?php endif; ?>
0

At the end, the issue has been resolved after I have installed the ubuntu on my laptop. So I can assume that it was something with my env configs.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.