Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

geerizzle's avatar

How to read any user’s session data?

Right now when my users add products to their shopping cart its stored in file system session.

Sometimes they go as far as creating an account but not then purchasing - so I want to automatically email them with one of those you left these products in your cart why dont you buy them type emails.

How do I get my server to know which session is for the relevant user and get the cart details from it? I see with database sessions it can be assigned to a user ID so is switching to dB sessions the only way?

0 likes
3 replies
jeffrey_no_way's avatar

why do you torture yourself so?

just create a cart and cart item table. you can always delete inactive carts later

geerizzle's avatar

Maybe that's the best way, I can see how this would work if I created it from the session when the user account got created. But what about before they have a User ID, can I use a cart table associated with sessions maybe?

jeffrey_no_way's avatar

just create a unique cookie value and store it in the db.

$cart_id = str_random(30);
cookie(['cart_id' => $cart_id]);
Cart::create(['cart_id' => $cart_id]);

and you can make user_id nullable

Please or to participate in this conversation.