How can I identify a guest user for a longer time than a session, as a rule, exists

I know what I can use \Session::getId(). But from time to time it changes. Maybe I do not understand the sessions. As I know, it starts when php starts and is deleted when php code completes. On the other hand, I read that the session identifier is stored in a cookie, and when the user opens your site again, the session is “restored”. So why in my case the session id expires so fast. How can I get a session identifier that does not change for at least a month and is used by carts?

Update: The question is getting a bit confusing because I don’t want to name some things and don’t know how it works.

I want to know how I can identify a guest user and get their unique identifier over a period of time (longer than usual sessions). As a result, I want to have a function someFunctionthat could do the following:

$guestId = someFunction();
$dbRow = Model::findByGuestIdOrNew($guestId);
// now $dbRow contains all previosly save info about a guest user, 
// of it does not exists, create new row by `$guestId`.

It seems to me that there is a unique session identifier that exists for a longer time than a session. This thought came to me when I saw that in most cases the baskets elements of the basket are stored directly in the session. I really don’t know how long these packages store goods in the basket, but I think this time more than a week. This period of time for the life of the trolley was determined by me when working with such trading platforms: shopify and bigcommerce . I know that they keep the basket for more than a week. Therefore, I want to know how they identify the guest user before creating an account. It will also be useful information to find out how long most shopping cart packages have been storing goods in a shopping cart.

+4
1

Laravel , , PHP Session Documentation. , :

- . . cookie , . cookie PHP , .

, , , , , , . , Laravel config/session.php:

'lifetime' => 120,

, 120 . , , , , :

'expire_on_close' => true,

Laravel Sessions Documentation, , Laravel , config/session.php, , .


, PHP Laravel, lifetime :

'lifetime' => 60*24*30 // 60 minutes x 24 hours x 30 days = 43200 minutes

, . , , , .


, Cartalyst Cart (, , Laravel) , , nice sync, , , . , :

// Get the items from the database
$items = CartItem::where('user_id', Auth::id())->get();

// Sync the items with the session cart
Cart::sync($items);

, cart_items CartItem Laravel Authentication , , , .

+5

Source: https://habr.com/ru/post/1618660/


All Articles