简体   繁体   English

如何知道用户是否使用其会话ID登录

[英]How to know if user is logged with his session id

I need to know if there is an user logged in my website. 我需要知道是否有用户登录我的网站。 For this purpose, I have only his session ID. 为此,我只有他的会话ID。

I got this id using: session->getId(); 我使用以下方法获取此ID: session-> getId();

¿Is it possible? 可能吗?

Thanks in advance. 提前致谢。

在用户登录时将自定义字段添加到会话中,然后仅检查该字段

Given that the web is essentially stateless, it is hard to know for sure if a particular user is logged onto a website. 鉴于Web本质上是无状态的,因此很难确定是否有特定用户登录到网站。

One way to accomplish your goal is to keep a running log of all the users logged in, and the last visit time. 实现目标的一种方法是保持所有已登录用户的运行日志以及上次访问时间。 Then you could query that log and if the users last visit time was less than 5 minutes ago, you could then say the user is logged onto your site. 然后,您可以查询该日志,如果用户的上次访问时间少于5分钟,则可以说该用户已登录到您的站点。 This will only tell you if the user is logged into your site, not if your site is the active tab in their browser. 这只会告诉您用户是否已登录到您的网站,而不是您的网站是否是其浏览器中的活动选项卡。

Another way to get more "real-time" information as to the the active users of your site is to use something like SignalR which will allow you to do push to the browser. 获取有关站点活动用户的更多“实时”信息的另一种方法是使用SignalR之类的东西 ,它将使您能够推送到浏览器。 I've used SignalR in the past to send out system status messages to the browser and have it automatically update the page. 我过去曾使用SignalR将系统状态消息发送到浏览器,并使其自动更新页面。 The great thing about SignalR is it maintains an in-memory list of all the clients connected. SignalR的伟大之处在于它维护了所有已连接客户端的内存列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查用户是否通过其会话在路由中登录,然后在laravel中调用控制器方法? - how to check if user is logged in by his session in route and then call controller method in laravel? 如何提取session登录用户的当前user_id? - How to extract the current user_id of the user logged in that session? 如何检查用户是否已连接并获取其会话ID(会话由PHP启动) - How to check if user is connected and get his session id (Session started by PHP) 如何使用 laravel 6 中的 session 从数据库中获取登录的用户 ID - How to get logged user id from database using session in laravel 6 如何知道用户是否已登录Zend - How to know if user is logged in Zend 启用PHP会话的页面如何知道用户从另一个页面登录? - How does a PHP session-enabled page know a user logged in from another page? 如何获取登录的用户ID - How to get the logged in user id 在用户使用其令牌登录以参加调查后进行Lime Survey,是否为用户维护了单独的会话? - Lime Survey after user logged in with his token to participate in survey, a separate session is maintained for users? 如何知道用户是否登录了Facebook? Laravel社交名流 - How to know if user is logged to Facebook? Laravel Socialite laravel 如何知道用户是否登录? - how does laravel know if the user is logged in?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM