且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP-停止并发用户登录

更新时间:2023-12-01 17:15:46

我需要找到一种方法,在浏览器关闭时执行脚本以更新数据库.

你不能.

您***的解决方案可能是将会话ID与数据库中的用户相关联.如果用户计算机上的会话ID与数据库中的最新会话ID不匹配,请让他们登录并更新数据库.

I need a method of stopping concurrent logins using PHP/MySQL.

The current setup

Currently there are 2 people sharing the same login on a system i have built internally where i work. Due to the nature of the system i dont want them both logging in.

What I have tried

Around 10 articles on *** and googled for as long as i can.

I also attempted adding a "loggedin" field in the user table which upon logging in was set to 1 and upon logging out was set to 0. Then if the same user credentials where used at login, it would fail.

The problem i had was that if the person who was logged in shut down the browser without logging out properly, it wasnt updating the database. Then i get a phone call from that person and i would have to reset the value to 0 in the database.

This isn't feasible going forward as the product is being rolled out to around 20 people internally soon.

What I need

What i need is to find a way that when the browser closes a script gets executed to update the database. Alternatively a way of reading every current session on the server, which i could manipulate, or something else.

Restrictions

Our hosting providers are awful and subsequently what changes i can make to the server are limited/impossible. The hosting is a shared hosting solution.

What i need is to find a way that when the browser closes a script gets executed to update the database.

You can't.

Your best solution may be associating the session ID with the user in the database. If the session ID on the user's computer doesn't match the most recent session ID in the database, make them log in and update the db.