Php+mysql a large number of user login solutions Analysis _php Skills

Source: Internet
Author: User
Tags md5

In this paper, we analyze the php+mysql of a large number of user login solutions. Share to everyone for your reference. The specific analysis is as follows:

Baidu, QQ, 360 and other large companies have hundreds of millions of users, not only all subsites are logged in through an account, but also open the user platform for other sites to use, this level of data volume and access, if not optimized, it is expected to soon downtime, these companies are a dedicated team, Maintenance of a registered login, the details of the design is very good, now a rough talk about their design plan.

Large data, the pressure is not in PHP, mainly in the mysql,php can do load balancing, 10 machines are not able to withstand the use of 20 or 100, which is not a bottleneck.

But MySQL is a single point, no matter how much from the library, is to optimize the query, update data can not simply through the addition of the machine to solve, and query also through the Memcache cache to reduce the pressure, so do not have to do how much from the library, General 1 Master 4 from on it can be.

The following is a description of the following database solution:

Assume that the user can log on through the login name, mailbox, or phone number.

The table structure is as follows:

Login name and ID table, according to Login_hash 100 sheets

Copy Code code as follows:
CREATE TABLE User_login (
Login_name VARCHAR () User logon name, can be "login name", "Mailbox" or "Phone number" login
Hash code for 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, 100 sheets according to USER_ID

CREATE TABLE User_info (
USER_ID BIGINT User ID
Login_pwd CHAR () User logon password
... ... Other information, home address, cell phone number, sex, 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: Implement a service with an ID (equivalent to Oracle's sequence) or implement it yourself (either with php+mysql or with C). The goal is to get the ID from this service, each time the number of IDs is based on the last +1, and the MySQL autoincrement very much like, just can't increase inside the table.

Registration process:

1 Verify the user name, mailbox, mobile phone number, password and other formats. Omitted...

2 Take an ID from the service, assuming it is 115.

3 If the user's logon type is a mailbox (such as: $loginName = ' songhuan@zixue.it '), prefix the login name with the name of the login (such as: $loginName = ' mail_songhuan@zixue.it ')

4) to find the hash value of the login name: $loginHash =md5 ($loginName); For MD5 value hash, you can find the ASC code, or use your own algorithm, and finally get $loginhash=16 bit or 32-bit integer

5) $tableName = ' User_login '. ($loginHash%100) if the User_login table name is obtained, if the result is user_login88.

$tableName = ' User_info '. (115%100) If the User_info table name is obtained.

6 Execute SQL:

Copy Code code 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 (UP, ' afieflefiefladifadfadfe ');

Login Process:

1 if the user's logon type is a mailbox (such as: $loginName = ' songhuan@zixue.it '), prefix the login name with the name of the login (such as: $loginName = ' mail_songhuan@zixue.it ')

2)

Copy Code code as follows:
$loginHash =ord (MD5 ($loginName));

3)

Copy Code code as follows:
$tableName = ' User_login '. ($loginHash%100);
If the result is user_login88

4 Execute SQL:

Copy Code code as follows:
SELECT ID from user_login88 WHERE login_hash = $loginHash;

If the query does not have the data, the sign-in name does not exist

5 if can obtain, id=115, then

Copy Code code 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 equal, return false

7 If the password is equal, the user ID is encrypted into a cookie, and the user information is stored in memcache.

I hope this article will help you with your PHP program design.

Related Article

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.