After logging into the system to understand how to operate the database,
And learn more about how the session was done.
You should know how to make a system.
The system is identical to the idea of an ASP login system in the article "ASP" connected to Access database login system (click to open link).
Just the programming language from ASP into PHP, the database from access to MySQL
I. BASIC OBJECTIVES
First, the following user information tables exist in MySQL:
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 is not at all, then the "Check No this Person" dialog box, and return to this page
If the user entered the wrong password, then the "Password Error" dialog box pops up and returns to this page
If the login information entered by the user is correct, then skip to the "Login successful" page and output the user's current IP, the locale of the system used, and the browser information
"Login Successful" page is protected, the browser can not enter the address in the browser, bypassing the password input page, direct access to the "Login Success" page
Second, the basic idea
The user enters the user name and password of the page with a static page, as long as its form points to the Login Judgment page login.php.
Welcome.php is the user's successful login page,
Exit.php is used to destroy the session.
The session is the browser global variable that holds the user name and password.
Third, the production process
(1) login.html
There's nothing to say, just a login form, see the following code:
Login Page
(2) exit.php
Destroy the session page, and after the session is destroyed, return the page to login.html
It is important to note that in PHP once you need to use the session, you should use Session_Start () in the first line of all the code, or the system function, or you may get an error.
Log Out page
(3) login.php
Login Judgment page, or classic sign-in syllogism,
First receive login.html pass over username and password, query the user Information table whether there is this username,
If not, then login failure, if any, and then determine whether the password, the user input is equal to the username in the database corresponding Dbpassword,
If it is, login successful, and put username into session, pass to login Success page, otherwise login failed.
This page also uses the system built-in function is_null to determine whether the query results are empty,
If the database query result is empty, there is no value assigned to the newly defined dbusername, and the dbusername is still empty
Also, if the login succeeds, use Mt_rand (0,100000) and generate a random number code to protect the login Success page in 0~100000.
And after all the judgment, remember to add a closed database at the end of the statement, people walk with the door.
Landing in ...
(4) welcome.php
In the welcome.php successful login page, the first to use isset to determine if there is login.php pass over the code,
Here the difference between the isset and the above Is_null, Isset is to determine if there is no such 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 a normal way to log in, immediately throw to exit.php goodbye to leave
If it is a normal login, the user information is output through the individual small objects inside the server object.
Welcome to Login
Welcome to login!
Your IP:
Your system language:
Your browser is:
Sign Out
At this point, the entire login system development is complete.