Build Web site: User's login Certification _php tutorial

Source: Internet
Author: User
Tags setcookie
Several of the features of PHP have been described earlier, and from now on, take advantage of the combination of these techniques to build a powerful website that will be followed by a number of advanced and basic tips on how to apply the site.
To build a good website, the user authentication function is essential, the same here I just introduce ideas and practices, and will not add duck step by stage listing steps.
First you need a database that can be used to record user data, which should include at least the name and password, and optionally add the appropriate fields to the database.
In order to make the database information, must have a registration process, through the registration of the user can be stored in the database, the implementation of the registration process is very simple, just send the instructions stored in the database, here is no longer described, here to put forward is, out of the user's data security considerations, it is best for the user's password encryption, And the database should not have the same name, otherwise it will be messed up.
The following focuses on user login and logout implementation, the user login function with session and cookie can be completed, I am here to describe how to use cookies to complete this function.
In fact, the user login to understand the entire process is very simple, the program will enter the user name and password and database stored data comparison, the database has this user's information is passed, did not deny the user through.
Take a look at the workflow of the login program login.php:
User Submissions to login,php,login.php will be processed as follows:
$PASSWD =md5 ($PASSWD);
$result =mysql_query ("select * from user where name= ' $name ' and passwd= ' $passwd '");
The reason that the password to go through MD5 processing, is because the database is stored by MD5 encrypted password, to determine if there is no such user exists, does not exist or password error to give some alarm to the user, the user's data, you can set the user's data to the cookie value, as follows:
Setcookie ("CookieName", $name, Time () +18000, "", "/");
Setcookie ("cookiepasswd", $passwd, Time () +18000, "", "/");
If you are concerned about a security problem that the user has forgotten to log out of, remove the time setting:
Setcookie ("CookieName", $name, "", "/");
Setcookie ("cookiepasswd", $passwd, "", "/");
This way, when the user closes the browser, the cookie settings expire, that is, the next time the user comes, you must re-login! Although there is a security feature that shuts down the browser to disable cookies, it is necessary for a user to log out of the function to security, logout function is to let the record user data The function of the cookie invalidation, it is very simple to complete this function, only need to set the time to 1, and the cookie variable blank on the line:
logout.php:
Setcookie (' CookieName ', "", Time ()-1, '/', "");
Setcookie (' cookiepasswd ', "", Time ()-1, '/', "");
$cookiename = "";
$COOKIEPASSWD = "";
Such a complete user authentication function is complete.


http://www.bkjia.com/PHPjc/445179.html www.bkjia.com true http://www.bkjia.com/PHPjc/445179.html techarticle I have introduced a few PHP functional skills, from now on to take full advantage of the combination of these techniques to build a powerful website, will be introduced in the future a number of advanced and basic skills ...

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