PHP Development Membership System

Source: Internet
Author: User
Tags php language md5 encryption

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:

  1. <?php

    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 <?php include ("config.php");

  2. if ($_post[' submit ']) {

    $username = Str_replace ("", "" ", $_post[' username ']);

    echo $username. " <br> ";

    $password = MD5 ($_post[' password '). ALL_PS);

    echo $password. " <br> ";

    $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";

    }

    }

    ?>

    <form action= "" method= "POST" >

    User name: <input type= "text" name= "username"/><br>

    Secret--code: <input type= "password" name= "password"/><br>

    <input type= "Submit" name= "submit" value= "register"/><br>

    </form>

    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,

    1. The Member login page is written. Create a new Member login page, named user.php. The specific code is as follows:

      <?php

      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. " <br> ";

      $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 ']. " <br> ";

      echo "Login Successful";

      }else{

      echo "User name or password error";

      Session_destroy ();

      }

      }

      ?>

      <form action= "" method= "POST" >

      User name: <input type= "text" name= "username"/><br>

      Secret--code: <input type= "password" name= "password"/><br>

      <input type= "Submit" name= "submit" value= "Login"/><br>

      </form>

    2. 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:

      <?php

      Include ("config.php");

      echo $_session[' uid ']. " <br> ";

      echo $_session[' User_shell '];

      $arr = User_shell ($_session[' uid '), $_session[' User_shell '], 4);

      Echo $_session[' Times ']. " <br> ";

      Echo Mktime ();

      echo "Username:" $arr [' username ']. " <br> ";

      echo "Password:". $arr [' Password ']. " <br> ";

      echo "m_id:". $arr [' m_id ']. " <br> ";

      User_mktime ($_session[' Times ');

      ?>

      Permission content

    3. 7

      At this point, one of our simple membership systems has been developed. Figure:

      At this point, Member login system design completed

      End, practice.



PHP Development Membership System

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.