Php+mysql Member System Development Example tutorial, mysql example tutorial _php tutorial

Source: Internet
Author: User

Php+mysql Member System Development Example tutorial, mysql example tutorial


In this paper, a simple example of the complete PHP+MYSQL member system functions. is a very practical application. The specific implementation steps are as follows:

First, the principle of membership system:

Login----keep status (cookie or session)--Verify status and its permissions

Second, the security of the member system:

1, learn to use constants to improve MD5 security
2, cookie/session less with clear text information
3. session security should be greater than cookie
4. Use Cookie/session to read information as far as possible to increase judgment information
5, cookie/session content to streamline
6, for the wrong information in time to destroy Cookie/session

Third, database test, table User_list, and its fields

UID m_id username password
1 1 Admin 291760f98414679e3fd3f9051b19b6f7
2 2 admin2 895785cfa5d8157f4d33c58ae0f55123

Password: MD5 (ADMINTEST100), MD5 (ADMIN2TEST100), respectively, after the password is bound to the constant test100, and then encrypted into the database, this step can be set at the time of registration.

Iv. Configuration page m_config.php:

<?php session_start (); Database connection $conn =mysql_connect (' localhost ', ' root ', '); mysql_select_db (' Test ', $conn); Define constants define (ALL_PS, "test100"); View login status and 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) {//$row [m_id] The smaller the privilege, the higher the 1 O'Clock permission       return $row;     } else{       echo "You do not have enough permissions to view this page";       Exit ();      }   } else{     echo "Login to view this page";     Exit ();    }  } Set Login timeout function user_mktime ($onlinetime) {    $new _time=mktime ();    echo $new _time-$onlinetime. " Seconds did not manipulate the page "."
"; if ($new _time-$onlinetime > ' 10 ') {//Set timeout of 10 seconds, test with echo "Login timeout, please login again"; Exit (); Session_destroy (); } else{ $_session[times]=mktime ();

Five, login page m_user.php:

<?php include ("m_config.php"); echo MD5 ("admin2"). ALL_PS); if ($_post[submit]) {  $username =str_replace ("", "", "$_post[username]");  $sql = "SELECT * from User_list where ' username ' = ' $username '";   $query =mysql_query ($sql);  $US =is_array ($row =mysql_fetch_array ($query));  $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 ();//Get Login to forget the time of the    echo "login successful";  } else{    echo "User name or password error";    Session_destroy ()///Password error when removing all session  }}?>

Six, set the permissions and Timeout page m_zhuangtai.php:

<?php include ("m_config.php");  $arr =user_shell ($_session[uid],$_session[user_shell],1);//Set this page to access user_mktime only if the permission is 1 o'clock  ($_session[ Times]);//Determine if the timeout is 10 seconds  //echo $_session[times]. "
";//login at the time//echo mktime ()."
";//Current date//echo $arr [username]."
"; echo $arr [uid]. "
";?>

Content that can be viewed by a privileged party

Vii. Test Results:

1, log in with sss,sssssss, prompt: User name or password error. To view m_zhuangtai.php, Tip: You can log in to view the page.
2, with admin admin login, because the permission is 1, so you can view the contents of the m_zhuangtai.php page.
3, with the admin admin login, because the permission is 1, so you can view the contents of the m_zhuangtai.php page, but after 10 seconds and then refresh, prompt: X seconds did not operate the page login timeout, please re-login.
4, with admin2 admin2 login, because the permission is 2, so can not view the contents of the m_zhuangtai.php page, tip: You do not have enough permissions to view the page.

I hope that the examples described in this article will help you to develop PHP programs.


Php+mysql Development Case Tutorial Code News system Code

The original book does not have a CD-ROM or something, you can consider contacting the author to see if I can give you. If not really, you can follow the contents of the book to do, the harvest will be small, there are problems, you can always ask me.

Source code for the Php+mysql Development Example Tutorial

Many online, do you need a framework or?

http://www.bkjia.com/PHPjc/868225.html www.bkjia.com true http://www.bkjia.com/PHPjc/868225.html techarticle Php+mysql Member System Development Example tutorial, mysql example tutorial this article through a simple instance completed the complete Php+mysql member system function. is a very practical application. Specific ...

  • 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.