Analysis of a large number of user login solutions for php + mysql, mysql User login _ PHP Tutorial

Source: Internet
Author: User
Analysis of a large number of user logon solutions for php + mysql, mysql user logon. Analysis of a large number of user login solutions for php + mysql, mysql User login examples in this article analyzed a large number of user login solutions for php + mysql. Share it with you for your reference. The specific analysis is as follows: php + mysql a large number of user login solutions analysis, mysql User Login

This article analyzes a large number of user logon solutions for php + mysql. Share it with you for your reference. The specific analysis is as follows:

Baidu, QQ, 360, and other large companies all have hundreds of millions of users. not only are all sub-websites logged on through one account, but also the user platform is also open for use by other websites, if the data volume and access volume at this level are not optimized, it is estimated that the system will be down soon. these companies are dedicated teams that maintain a registered login. the detailed design is excellent, now let's take a rough look at their design solutions.

When using big data, the pressure is not in PHP, but mainly in MySQL and PHP, which can be used for load balancing. 20 or 100 servers can be used if 10 servers cannot resist, which is not the bottleneck.

However, MySQL is single-point. no matter how many slave databases are used, it is optimized for queries. updating data cannot be simply solved by adding machines. In addition, queries can also reduce the pressure through Memcache Cache, therefore, you do not need to perform many slave databases. generally, one master and four slave databases are enough.

The following describes the database solutions:

Assume that you can log on through the "login name", "email", or "mobile phone number.

The table structure is as follows:

The login name and ID table, which are divided into 100 tables according to login_hash

The code is as follows:

Create table user_login (
Login_name VARCHAR () user logon name, which can be "login name", "email", or "mobile phone number"
The HASH code of the login_hash BIGINT user login name
User_id BIGINT user ID
);
Create table user_login0 LIKE user_login;
Create table user_login1 LIKE user_login;
... ...
Create table user_login100 LIKE user_login;
ID and user information table, which are divided into 100 tables according to user_id

Create table user_info (
User_id BIGINT user ID
Login_pwd CHAR () user logon password
... ... Other information, home address, mobile phone number, gender, etc.
);

Create table user_info0 LIKE user_info;
Create table user_info1 LIKE user_info;
... ...
Create table user_info2 LIKE user_info;


Business implementation logic:

Dependent server: implements an auto-incremental ID service (equivalent to the sequence of oracle), or you can implement it yourself (either using PHP + MySQL or using C ). The purpose is to obtain the ID from this service. the number of IDs obtained each time is plus 1 on the basis of the previous time, which is similar to the autoincrement of MySQL, but cannot be auto-incremented within the table.

Registration process:

1) verify the format of the user name, email address, mobile phone number, and password. Omitted...

2) obtain an ID from the service, which is assumed to be 115.

3) If the user's logon type is email (for example, $ loginName = 'songhuan @ zixue. it '), then the prefix login name result is added before the login name (for example: $ loginName = 'mail _ songhuan@zixue.it ')

4) calculate the HASH value of the login name: $ loginHash = md5 ($ loginName); calculate the asc code for the md5 value hash, or use your own algorithm, finally, we can get the $ loginHash = 16-bit or 32-bit integer.

5) $ tableName = 'User _ login'. ($ loginHash % 100). If the user_login table name is obtained, the result is user_login88.

$ TableName = 'User _ info'. (115% 100). If you get the user_info table name.

6) execute SQL:

The code is as follows:

Insert into user_login88 (login_name, login_hash, user_id) VALUES ('songhuan @ zixue. it', 183239324323, 1 );
Insert into user_info15 (user_id, login_pwd) VALUES (115, 'afieflefiefladifadfadfe ');


Logon process:

1) if the user's logon type is email (for example, $ loginName = 'songhuan @ zixue. it '), then the prefix login name result is added before the login name (for example: $ loginName = 'mail _ songhuan@zixue.it ')

2)

The code is as follows:

$ LoginHash = ord (md5 ($ loginName ));

3)

The code is as follows:

$ TableName = 'User _ login'. ($ loginHash % 100 );

Assume that the result is user_login88.

4) execute SQL:

The code is as follows:

SELECT id FROM user_login88 WHERE login_hash = $ loginHash;

If no data is found, the login name does not exist.

5) If you can obtain the id = 115

The code is as follows:

$ TableName = 'User _ info'. (115% 100 );

SELECT id, pwd... FROM user_info15 WHERE id = 115;

6) match the password. if the password is not the same, false is returned.

7) If the password is the same, encrypt the user ID into the COOKIE and save the user information to Memcache.

I hope this article will help you with php programming.

In this article, we analyze the logon solution for a large number of php + mysql users. Share it with you for your reference. The specific analysis is as follows :...

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.