cancel
Showing results for 
Search instead for 
Did you mean: 

Handing Session Variables

SOLVED

Handing Session Variables

I am getting Sessions cleared in my app and this makes the values lost. I am using the Session variables to avoid calling duplicate functions in different API's. The Session variable works perfectly but only problem it gets cleared regularly and the values gets lost. How to solve this. My code for handling Session keys are below

 

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
$customerSession->setMyValue('0');

if ($customerSession->getMyValue() == '0')
            //Process my function


The $customerSession->getMyValue() works in multiple files, but fails after session expires. Anyway to fix this?

 

Regards

Ansif

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Handing Session Variables

Sorry for the late reply. I was using an external API library to send and receive functions and this causes the Session and Cookie variables getting cleared. Anyway I have solved it using an Order variable which in my case works perfectly.

 

Thanks for your support

View solution in original post

2 REPLIES 2

Re: Handing Session Variables

Hello @ansif_ibrahimkutty ,

 

Do you want to increase the session time ? you can do as per this guide :

https://docs.magento.com/user-guide/customers/customer-online-options.html

 

if you don't want to increase how you will get session ? the other way is to use cookie management.

 

hope it helps !

Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy

Re: Handing Session Variables

Sorry for the late reply. I was using an external API library to send and receive functions and this causes the Session and Cookie variables getting cleared. Anyway I have solved it using an Order variable which in my case works perfectly.

 

Thanks for your support