Php + MySql implements the login system and output viewer information function, phpmysql

Source: Internet
Author: User

Php + MySql implements the login system and output viewer information function, phpmysql

The idea of this system is exactly the same as that of ASP login System in asp connection Access Database (click to open the link), except that the programming language changes from asp to php, the database changes from Access to mysql.

I. Basic Objectives

First, the following user information table exists in mysql:


There is a logon form on the page. You need to enter the user name, password, and other information.

If the user name entered by the user does not exist in the user information table, the "check for this person" dialog box will pop up and return to this page.


If the password entered by the user is incorrect, the "Incorrect password" dialog box is displayed, and the system returns to this page.


If the login information entered by the user is correct, the "Login successful" page is displayed, and the current IP address, the language environment of the system used, and browser information are output.


The "Login successful" page is protected, and the browser cannot bypass the Password Input page by entering the address in the browser, directly accessing the "Login successful" Page


Ii. Basic Ideas


The page on which the user enters the user name and password uses a static page, as long as the form points to the logon judgment page login. php.

Welcome. php is the page on which the user successfully logs on,

Exit. php is used to destroy the session.

Session is a global browser variable used to store user names and passwords.

Iii. Production Process
 (1)login.html
There is 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

Describe the sessionpage, and after describe the session, roll the page back to login.html
It is worth noting that once session is used in php, session_start (); system function should be used in the first line of all code; otherwise, an error may occur.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

(3) login. php

The logon page is also a classic example. First, the system receives the username and password passed by login.html to check whether the username exists in the user information table. If no, the system fails to log on. If yes, at the same time, determine whether the user-Entered password is the same as the dbpassword corresponding to this username in the database. If yes, the logon succeeds, and the username is saved to the session and passed to the logon success page, otherwise, the logon fails.
This page also uses the built-in system function is_null to determine whether the query result is null. If the database query result is empty, no value is assigned to the newly defined dbusername. This dbusername is still empty.
At the same time, if the logon is successful, you must use mt_rand ~ 100000 generates a random number code to protect the logon success page.
After making all the judgments, remember to add a statement to close the database.

<! 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. on the php logon page, use isset to determine whether login exists. the code passed by php. Here the difference between isset and is_null is that isset is used to determine whether this variable exists, and is_null is used to determine whether the variable is null, if there is no code for this session, it indicates that the user has logged on through an abnormal way and is immediately thrown to exit. php goodbye
If the logon is normal, the user information is output through each small object in the server object.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

So far, the entire login system has been developed.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.