Welcome Guest, Not a member yet? Register   Sign In
Session data lost after redirect randomly (CI4.1.5)
#1
Photo 
(This post was last modified: 08-23-2022, 03:58 AM by pJenkiss.)

Hello,
I wrote a post some time ago about another issue (https://forum.codeigniter.com/showthread.php?tid=80668), but I still facing various issues with lost session data from time to time. And I have no idea what I do wrong, because it happens randomly. I catched this situation in logs (see image below). The situation:
I add products to "cart" and save it to session. Then redirect to cart page and show cart details. However, from time to time the cart appears to be empty, even though it was added successfully. 
Here is my last line in "cart edit" controller function:
PHP Code:
$sessionData = ['cart' => $cart'orderId' => $order['id']];
$this->session->set($sessionData);
log_message('error''Debug: add to cart, session set: '.json_encode($_SESSION));
return 
redirect()->to('/cart'); 

This is the beginning of the code from "cart" controller function:
PHP Code:
log_message('error''Debug: cart init, session: '.json_encode($_SESSION)); 

In the image you can see two attempts to add new product to a cart, first time product was added and after redirect it stayed in the session, second time cart was not there after redirect. Sometimes I need to repeat the cycle 3, sometimes - 5 times in order session to keep data after redirect.
Any ideas at what to look at? 
I work on single tab, session expiration is set for 1 month. 
I work with CI for years, but since we moved to version 4 earlier this year session issues keep bugging me.. 
[Image: Screenshot-2022-08-23-134322.jpg]
Reply


Messages In This Thread
Session data lost after redirect randomly (CI4.1.5) - by pJenkiss - 08-23-2022, 03:56 AM



Theme © iAndrew 2016 - Forum software by © MyBB