PHP implementation of the same account can only one person login
Zhang Ying published in 2015-01-22
Category: PHP
Before considering this problem, today achieved a bit, quite fast, from research to development completed almost 4 hours. A bit like QQ, two computers log in, one will put another one to squeeze off the line, and prompted other locations login information.
One, the realization principle
1, the user logs on at computer A, session information is stored in the Redis, and the session_id stored in the MySQL database.
2, the same user in Computer B login, after verifying the user name and password, the user information from the database read out, get the user in Computer a login session_id, and then in the Redis to verify whether the session expires.
3, if it expires, do not openfire push prompt message. If there is no expiration, PHP after using OpenFire push message, in the Redis users in computer A login session deleted, deleted, in the user's computer B log on the personal information in the session, and the computer B log on the session_id update to the database , you must first send the push, and then clear the session, or the user in computer A will not receive the message XMPP sent over.
Attention:
OpenFire is a Java CMS, you have a database, you create a user table root OpenFire comes with a user table to establish a connection (such as: Mobile phone number, mailbox, etc.), convenient information push.
The same session_id must be logged in the same media, and this time, there is no need to update the database and push messages
Here's a brief look at the installation process and where to look.
Second, the installation of the tools used
- # yum install php php-fpm nginx mysql mysql-server redis php-redis php-devel php-pdo php-mysql
To modify the session storage mode:
View copy print?
- # vim/etc/php-fpm.d/www.conf
- ;p Hp_value[session.save_handler] = files //comment out the old
- ;p Hp_value[session.save_path] =/var/lib/php/session
- Php_value[session.save_handler] = Redis //Add the following
- Php_value[session.save_path] = "tcp://127.0.0.1:6379"
After the service is started, session Redis succeeds if the following is indicated
Redis Telnet View Session
openfire:http://www.igniterealtime.org/downloads/
View copy print?
- # RPM-IVH./*.rpm //download RPM installation package
OpenFire boot, and then access to http://ip:9090, step by step configuration becomes, one thing to note is the database encoding.
For PHP operations and command-line operations for Redis, refer to:
Http://blog.51yip.com/?s=redis
PHP implementation of the same account can only one person login