"PHP" login system and output browser information

Source: Internet
Author: User

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:

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

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

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

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

<! 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 is complete.

"PHP" login system and output browser information

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.