PHP implementation of the same account can only one person login

Source: Internet
Author: User

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

    1. # 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?
    1. # vim/etc/php-fpm.d/www.conf
    2. ;p Hp_value[session.save_handler] = files //comment out the old
    3. ;p Hp_value[session.save_path] =/var/lib/php/session
    4. Php_value[session.save_handler] = Redis //Add the following
    5. 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?
    1. # 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.