Php+mysql a large number of user login solutions

Source: Internet
Author: User
Tags hash md5

Large data, the pressure is not in PHP, mainly in MySQL.
PHP can do load balancing, 10 machines will not withstand the use of 20 or 100 units, this is not a bottleneck.
But MySQL is a single point, no matter how much from the library, are optimized query, update data can not simply by adding a machine to solve.
And the query can also reduce the pressure through the memcache cache, so do not have to do how much from the library, General 1 Master 4 from on it.
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
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:
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 ');

Logon Process Www.111cn.net
1 if the user's logon type is a mailbox (such as: $loginName = ' songhuan@zixue.it '), prefix the login name with the result of the login (such as: $loginName = ' Mail_ Songhuan@zixue.it ')
2) $loginHash =ord (MD5 ($loginName));
3) $tableName   = ' user_login '. ($loginHash%100); If the result is User_login88
4) executes the Sql:select ID from user_login88 WHERE login_hash = $loginHash;
If the query does not have data, the sign-in name does not exist
5 if can obtain, id=115, then $tablename  = ' user_info '. (115%100);
SELECT ID, pwd ... From user_info15 WHERE id = 115;
6 matches the password, if the password is not equal, returns false
7 if the password is equal, the user ID is encrypted into a cookie, and the user information is stored in the Memcache

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.