PHP-停止并发用户登录 [英] PHP - Stop Concurrent User Logins

查看:101
本文介绍了PHP-停止并发用户登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种使用PHP/MySQL停止并发登录的方法.

当前设置

目前,有2个人在我内部工作的系统上共享相同的登录名.由于系统的性质,我不希望他们都登录.

我尝试过的事情

关于stackoverflow的大约10篇文章,并且在我可以搜索的范围内一直用Google搜索.

我还尝试在用户表中添加一个登录"字段,该字段在登录时设置为1,在注销时设置为0.然后,如果在登录时使用相同的用户凭据,它将失败. >

我遇到的问题是,如果登录的人在没有正确注销的情况下关闭了浏览器,则不会更新数据库.然后我接到那个人打来的电话,我必须将数据库中的值重置为0.

这是不可行的,因为该产品即将在内部向大约20个人推出.

我需要的

我需要的是找到一种方法,当浏览器关闭时,将执行脚本来更新数据库.或者,一种读取服务器上每个当前会话的方式(我可以操纵),或者其他方式.

限制

我们的托管服务提供商非常糟糕,因此我可以对服务器进行的更改有限/不可能.托管是共享的托管解决方案.

解决方案

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

你不能.

您最好的解决方案可能是将会话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 stackoverflow 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.

这篇关于PHP-停止并发用户登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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