有人可以解释会话表laravel [英] Can someone explain session table laravel

查看:192
本文介绍了有人可以解释会话表laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我想检查我的用户是否在线,我认为一个很好的方法是使用laravel提供的会话表。

Ok so I want to check if my users are online or not, I think a good way of doing this is using the sessions table that laravel provides. I'm a newbie though so can anybody first of all explain to me what this data means.

CREATE TABLE 会话
id VARCHAR(40)NOT NULL,
last_activity NULL,
data TEXT NOT NULL,
PRIMARY KEY( id
);

CREATE TABLE sessions ( id VARCHAR(40) NOT NULL, last_activity INT(10) NOT NULL, data TEXT NOT NULL, PRIMARY KEY (id) );

last_activity是一个unix时间戳,对我很清楚。

last_activity is a unix timestamp, that one is clear to me.

我的id = lGBzJ0dIWiebrwjFlkQAE19NHuNHvsPRVS7e4CRO

My id = lGBzJ0dIWiebrwjFlkQAE19NHuNHvsPRVS7e4CRO

这等于cookie值,但对我来说并不多。

This is equal to the cookie value but that doesn't say all that much to me.

data:a:3:{s:5::new:; a:0:{} s:5::old:; a:0:{} s:10:csrf_token :XOZbMp8mrVUbu2Lk4c1cEdCoJUQIL3tSeHaztH1v;}

and my data = a:3:{s:5:":new:";a:0:{}s:5:":old:";a:0:{}s:10:"csrf_token";s:40:"XOZbMp8mrVUbu2Lk4c1cEdCoJUQIL3tSeHaztH1v";}

这些2是什么意思,我如何使用它们从他们在laravel中导出用户ID?

What do these 2 mean and how can I use them to derive a user id from them in laravel?

推荐答案

Laravel不会直接在会话表中存储对用户的引用。对于拥有会话的会话系统来说没有关系,并且可能存在没有用户附加到他们的会话(即,在某人登录之前)。

Laravel does not store a reference to the user directly on the sessions table. It does not matter to the session system who owns the session, and there may be sessions with no user attached to them (i.e., before someone has logged in).

数据列是 PHP序列化,因此如果您真的想读取该数据,则可以。

The data column is PHP serialized so if you really want to read that data you can.

Laravel将会话数据分为三类:持久化,旧的闪存数据,新的闪存数据。这是为什么你会发现两个数组:new:和:old:在你的粘贴代码中是空的。

Laravel breaks session data in to 3 categories: persistent, old flash data, new flash data. This is why you will find two arrays ":new:" and ":old:", empty in your pasted code.

为什么您的用户表格上没有上次上线时间列,每次用户加载网页时触摸该列,自上次上线以来x分钟,那么他们可以被视为在线?

Why don't you have a "last seen" column on your users table, touch it each time a user loads a page, and if it's < x minutes since they were last seen then they can be considered "online"?

这篇关于有人可以解释会话表laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆