远程销毁php中的会话(用户在其他地方登录)? [英] Remotely destroy a session in php (user logs in somewhere else)?

查看:134
本文介绍了远程销毁php中的会话(用户在其他地方登录)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我试图让我的php网站基本上在同一用户登录其他地方时注销"(session_destroy()).有没有办法做到这一点?要远程销毁特定会话?

Hey, I'm trying to get my php website to basically "log out" (session_destroy()) when the same user logs in somewhere else. Is there a way to do this? To remotely destroy a specific session?

谢谢大家!

斯科特

推荐答案

使用 session_id .当用户登录其他地方时,您可以在开始新会话以进行新登录之前执行此步骤:

It's certainly possible, using session_id. When the user logs in somewhere else, you can do this step before starting a new session for the new login:

// The hard part: find out what $old_session_id is

session_id($old_session_id);
session_start();
session_destroy();

// Now proceed to create a new session for the new login

这将破坏服务器端的旧会话,因此,当另一台计算机再次访问您的应用程序时,它将尝试访问不存在的会话,并为此创建一个新的会话(在该用户中未登录用户) ).

This will destroy the old session on the server side, so when the other computer accesses your application again it will try to access a non-existent session and a new one will be created for it (in which the user is not logged in anymore).

困难的部分是找出旧"会话的ID是什么.没有一种千篇一律的方法可以做到这一点.您需要具备某种机制才能区分ID为XXX的会话属于当前登录的同一用户.如果您正在使用数据库会话,这应该很容易.

The hard part is finding out what is the ID of the "old" session. There's no one-size-fits-all way of doing that; you need to have some mechanism in place to be able to tell that the session with id XXX belongs to the same user who is logging in now. If you are using database sessions this should be easy enough.

这篇关于远程销毁php中的会话(用户在其他地方登录)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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