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();
}
  • clear browser cookies and try again – Murtuza Zabuawala Nov 22 '17 at 14:30
  • This was the first thing which I did and also, I have tried to use different browser – esigns Nov 22 '17 at 14:40
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; ?>
| improve this answer | |
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.

| improve this answer | |

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.