一个系统允许同一个帐号最多10个人同时登录在线,如何做呢
一个系统允许同一个帐号最多10个人同时登录在线,怎么做呢?
一个系统允许同一个帐号最多10个人同时登录在线,怎么做呢?说说大家的思路。。
------解决方案--------------------
是内部系统么。
建一个表logs表
ip user_id last_time
假设10分钟内算为在线
WHERE last_time+600 > time() 加 GROUP BY user_id 大于10个的话就不允许登录咯。
last_time+600
具体还得实践测试……
------解决方案--------------------
登陆是登陆,限制是限制。
一个登陆一个session,和普通的用户没有任何区别。
限制是额外的附加,每个账号一个数据库计数字段即可,问题是如何给让某个user的某个登陆过期。
用户每次都注销的话,那么操作数据库-1就好了。 用户不注销的话,那么数据库应该在session过期的同时计数-1,这样才对用户比较合理。但是很难让session的有效期和计数-1自动的关联运行, 也就是某个登陆session过期了,而数据库里还没有-1,这对用户就不公平了。
所以,如果能够注册一个session过期的回调来操作数据库计数-1就好了,可惜不知道有没有php.ini可以配置调用个回调php文件? 估计没有。。
所以,我最终给出的方案为:用户不注销就永远保持其登陆状态,依靠一个单独的COOKIE维护。。。由crontab跑一个php定时脚本,对那些登陆状态保持超过N长的人删除其数据库的COOKIE记录并给技术-1,这样就让位其他用户了,而且原先登陆的那位同学也没话可说,只能重新试图登陆了。
增加一张表:AUTO_ID USER COOKIE, 每个USER的每个登陆点对应一个COOKIE,限制该表同一个USER的COOKIE不超过10即限制了10人登陆,只要把COOKIE生成发给每个登陆者,只要它们不注销,它们在一段时间内都保持在线,PHP检测他们是谁与否就是用查数据库里的COOKIE。为了清理那些没注销的用户,只能跑crontab定时清理了。
总结!~~~~~ 其实就是因为SESSION总会过期,过期了就无从追踪了,所以需要把会话持久化到数据库!!!
再其次,因为SESSION过期没法回调函数,所以只有持久化之后定期跑crontab清理超时COOKIE~~~~
------解决方案--------------------
------解决方案--------------------
定制你的session handler即可,好处是不需要改动其它地方的代码
http://ca3.php.net/manual/en/class.sessionhandler.php
当然某些楼上的方法也都可以做到
看你自己的具体需求和现有实现而定
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
