PHP+MYSQL realization of login system and Output viewer information function _php skills

Source: Internet
Author: User

The system, with the previous "ASP connection Access database login System" (Click to open the link) in the article of the ASP login system is exactly the same, but the programming language from ASP into PHP, the database from access into MySQL.

I. BASIC OBJECTIVES

First in MySQL there are the following user information table:


In the page there is a login form, which requires users to fill in the user name and password information

If the user entered the user name in the User Information table does not have, then pop-up "No this person" dialog box, and return to this page


If the user enters a wrong password, the "Password Error" dialog box pops up and returns to this page


If the user enters the correct login information, skip to the "Login successful" page and output the user's current IP, the locale of the system used, and the browser information


The "Login successful" page is protected and the browser does not have access to the "Login Success" page by bypassing the password-entry page by entering the address in the browser.


Ii. Basic Ideas


The user enters the user name and the password the page to use the static page, as long as its form points to the Login Judgment page login.php to be possible.

welcome.php is the page where the user successfully logs on.

Exit.php is used to destroy sessions.

A session is a browser global variable used to hold a username and password.

Third, the production process
(1) login.html
There's nothing to say, just a login form, see the following code:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
 
 

(2) exit.php

Destroy the session page, and after the session is destroyed, return the page to login.html
It is worth noting that once you need to use the session in PHP, you should use Session_Start () in the first line of all the code, or you may have an error

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
 
 

(3) login.php

Login to judge the page, or the classic three-paragraph login, the first to receive login.html pass over the username and password, query the user Information table whether there is this username, if not, and then login failed, if there is, and then at the same time judge passed over, User input password is equal to this username in the database corresponding to the Dbpassword, if it is, login successfully, and the username into the session, passed to the Login Success page, otherwise login failed.
This page also uses the system built-in function is_null to determine whether the query result is empty, if the result of the database query is empty, there is no value given to the new definition of Dbusername, the dbusername is still empty.
Also, if the login succeeds, use Mt_rand (0,100000), and a random number code in 0~100000 to protect the successful login page.
and after doing all the judgment, remember to add a closing statement at the end of the database, people walk with the door.

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  

(4) welcome.php

In welcome.php successful login page, first to use isset to determine whether there are login.php passed over the code, here Isset and above is_null difference, isset is to judge whether there is no this variable, Is_null is in the premise of this variable, To determine whether this variable is null, if there is no code this session indicates that the user is not the normal way to log in, immediately throw to exit.php goodbye leave
If it is a normal login, the user information is exported through small objects within the server object.

 <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
 
 

At this point, the entire login system development completed.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.