Learning PHP for a long time, also familiar with the PHP language, want to design a simple membership system, including: Create database and table, member registration, member login, member permissions settings. Knowledge points involved: MD5 encryption, cookie/session creation, use, destruction, etc. Here is a detailed description of how to develop a simple membership system.
one,window+apache+mysql+php Integrated development environment, you can download on the Internet.
Create databases and tables. In Phpadmin, create a database named member, in which a membership table is created, with the table named: User_list, where the main fields include: UID (Member ID value), m_id (Member privilege), username (user name), password (password). A detailed description of the fields in the table is given in the following table:
Both, write a configuration file. The profile key information: Open session settings, connect to the database, password security additional information, the user to determine whether the user is logged on, and whether they have access to the function, to see whether the member login time-out function. The specific code is as follows:
Open Session Settings
Session_Start ();
Connecting to a database
$conn =mysql_connect (' localhost ', ' root ', ');
mysql_select_db (' member ', $conn);
Password Security additional information
Define (All_ps, "PHP100");
The user determines whether the user is logged on, and whether they have access rights
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 "You have insufficient authority";
Exit ();
}
}else{
echo "You have no access to this page";
Exit ();
}
}
See if a member login timed out
function User_mktime ($onlinetime) {
$new _time = Mktime ();
if ($new _time-$onlinetime > ' 10 ') {
echo "Login Timeout";
Session_destroy ();
}else{
$_session[' Times ' = Mktime (); Update Current time
}
}
?>
The Member registration page is written. Create a new Member registration page, named login.php. The specific 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);
Get the number of rows affected
$row =mysql_affected_rows ($conn);
if ($row >0)
{
echo "registered successfully";
}else{
echo "Failed to register";
}
}
?>
Register for membership. Here we can use the registration page we write to register the member, the registration information will be added to the corresponding database,
The Member login page is written. Create a new Member login page, named user.php. The specific 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 (); Time of Login
Echo $_session[' Times ']. "
";
echo "Login Successful";
}else{
echo "User name or password error";
Session_destroy ();
}
}
?>
Create a page for member access. Create a new user interface, named user_sys.php, this page is to make the member login and whether there is access to the settings, the specific 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
At this point, one of our simple membership systems has been developed. Figure:
At this point, Member login system design completed
End, practice.