PHP member system development

Source: Internet
Author: User
PHP has been developing a membership system for a long time. I am familiar with the PHP language and want to design a simple membership system. The content includes: create databases and tables, member registration, member logon, and member permission settings. Knowledge points involved: md5 encryption, Cookie/Session creation, use, and destruction. The following describes how to develop a simple membership system.

One, Window + Apache + MySQL + PHP integrated development environment, you can download it online.

Create databases and tables. Create a database named member in phpAdmin and create a member table named user_list. The main fields include uid (member ID value) and m_id (member permission) username and password ). The fields in the table are described as follows:

Two: write a configuration file. Main information of this configuration file: enable Session settings, connect to the database, add password security information, and determine whether the user is logged on and whether the user has access permissions; function used to check whether a member logon times out. The code is as follows:

// Enable Session settings

Session_start ();

// Connect to the database

$ Conn = mysql_connect ('localhost', 'root ','');

Mysql_select_db ('member', $ conn );

// Additional password security information

Define (ALL_PS, "PHP100 ");

// The user determines whether the user is logged on and whether the user has access permissions.

Function user_shell ($ uid, $ shell, $ m_id ){

$ SQL = "select * from user_list where uid = '$ uid '";

$ Query = mysql_query ($ SQL );

$ Us = is_array ($ row = mysql_fetch_array ($ query ));

$ Shell = $ us? $ Shell = md5 ($ row ['username']. $ row ['password']. ALL_PS): FALSE;

If ($ shell ){

If ($ row ['m _ id'] <= $ m_id ){

Return $ row;

} Else {

Echo "your permissions are insufficient ";

Exit ();

}

} Else {

Echo "you are not authorized to access this page ";

Exit ();

}

}

// Check whether the member logon times out

Function user_mktime ($ onlinetime ){

$ New_time = mktime ();

If ($ new_time-$ onlinetime> '10 '){

Echo "logon timeout ";

Session_destroy ();

} Else {

$ _ SESSION ['Times '] = mktime (); // update the current time

}

}

?>

Member registration page. Create a new member registration page named login. php. The code is as follows:

If ($ _ POST ['submit ']) {

$ Username = str_replace ("", "", $ _ POST ['username']);

Echo $ username ."
";

$ Password = md5 ($ _ POST ['password']. ALL_PS );

Echo $ password ."
";

$ SQL = "insert into user_list (uid, m_id, username, password) values (null, '0', '$ username',' $ password ')";

$ Query = mysql_query ($ SQL );

// Obtain the number of affected rows

$ Row = mysql_affected_rows ($ conn );

If ($ row> 0)

{

Echo "registration successful ";

} Else {

Echo "registration failed ";

}

}

?>

Register a member. Here, we can register members through the registration page we have compiled. After registration, the information will be added to the corresponding database,

Member logon page. Create a new member login page named user. php. The code is as follows:

Include ("config. php ");

If ($ _ POST ['submit ']) {

$ Username = $ _ POST ['username'];

$ SQL = "select * from user_list where username = '$ username '";

$ Query = mysql_query ($ SQL );

$ Us = is_array ($ row = mysql_fetch_array ($ query ));

Echo $ us ."
";

$ Ps = $ us? Md5 ($ _ POST ['password']. ALL_PS) = $ row ['password']: FALSE;

If ($ ps ){

$ _ SESSION ['uid'] = $ row ['uid'];

$ _ SESSION ['User _ Shell'] = md5 ($ row ['username']. $ row ['password']. ALL_PS );

$ _ SESSION ['Times '] = mktime (); // logon time

Echo $ _ SESSION ['Times ']."
";

Echo "logon successful ";

} Else {

Echo "incorrect user name or password ";

Session_destroy ();

}

}

?>

Create a page accessed by a member. Create a new access page named user_sys.php. on this page, you need to set the logon and access permissions of members. the code is as follows:

Include ("config. php ");

// Echo $ _ SESSION ['uid']."
";

// Echo $ _ SESSION ['User _ Shell'];

$ Arr = user_shell ($ _ SESSION ['uid'], $ _ SESSION ['User _ Shell'], 4 );

Echo $ _ SESSION ['Times ']."
";

Echo mktime ();

Echo "username:". $ arr ['username']."
";

Echo "password:". $ arr ['password']."
";

Echo "m_id:". $ arr ['m _ id']."
";

User_mktime ($ _ SESSION ['Times ']);

?>

Permission content

7

So far, a simple Member system has been developed. Figure:

So far, the member login system has been designed

End, exercise

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.