Php login system simplified version, php login simplified version
Logging on to the registration system is the most common operation for daily Internet access. I have set up a classification to improve the registration and logon system step by step. If there is any error, please forgive me.
Language used:Php
Database:Mysql
This implementation function:
1. User Registration
2. User Logon
Main files:
Complete code
1. SQL creates the user table, id, username, and password fields in an existing database.
Copy codeThe Code is as follows: create table user (id int (10) not null auto_increment, username varchar (30), password varchar (40), primary key (id ));
2 connect. php Database Configuration File
<? Php $ server = "localhost"; // host $ db_username = ""; // your database username $ db_password = ""; // Your Database Password $ con = mysql_connect ($ server, $ db_username, $ db_password); // link to the database if (! $ Con) {die ("can't connect ". mysql_error (); // if the link fails to output an error} mysql_select_db ('test', $ con); // select the database (my name is test)?>
3 signup.html registry ticket
<! Doctype html>
4 signup. php Registration Program
<? Php header ("Content-Type: text/html; charset = utf8"); if (! Isset ($ _ POST ['submit ']) {exit ("error execution ");} // determine whether there is a submit operation $ name =$ _ POST ['name']; // obtain the name $ password in the form using post =$ _ POST ['Password']; // post to obtain the password include ('connect. php '); // connect to the database $ q = "insert into user (id, username, password) values (null,' $ name', '$ password ')"; // Insert the SQL $ reslut = mysql_query ($ q, $ con) from the form to the database; // Execute SQL if (! $ Reslut) {die ('error :'. mysql_error (); // If the SQL Execution fails to output an error} else {echo "registered successfully"; // The output is successfully registered} mysql_close ($ con ); // close the database?>
The registration process is complete. The following figure shows the user logon process.
5 login.html login form
<! Doctype html>
6 login. php login program
<? PHP header ("Content-Type: text/html; charset = utf8"); if (! Isset ($ _ POST ["submit"]) {exit ("misexecuted");} // checks whether the submit operation include ('connect. php '); // link to the database $ name =$ _ POST ['name']; // obtain the username form value from post $ passowrd =$ _ POST ['Password']; // post to obtain the single user password value if ($ name & $ passowrd) {// If neither user name nor password is blank $ SQL = "select * from user where username = '$ name' and password =' $ passowrd '"; // check whether the database has the corresponding username and password SQL $ result = mysql_query ($ SQL); // Execute SQL $ rows = mysql_num_rows ($ result ); // returns a value if ($ Rows) {// 0 false 1 true header ("refresh: 01_url1_welcome.html"); // if it succeeds, exit from the welcome.html page;} else {echo "incorrect user name or password "; echo "<script> settimeout(function({{w.location.href}'login.html ';}, 1000); </script>"; // if an error occurs, skip to the logon page and try again in 1 second ;}} else {// if the user name or password is empty, echo "the form is not complete"; echo "<script> settimeout(function({{{location.href}'login.html ';}, 1000); </script> "; // skip to the logon page one second after js is used incorrectly and try again.} mysql_clo Se (); // close the database?>
7. Successful Logon to welcome.html
<! Doctype html>
So far, a simple and complete registration and login system has been completed, and the code is very simple without considering the security robustness of the verification, which will be improved later.
I hope this article will help you learn php programming.
Articles you may be interested in:
- PHP + AJAX for refreshing registration (Real-Time Detection with user names)
- Solve phpmyadmin #2002 failure to log on to MySQL Server
- Use Php to write the instance code for Email activation verification after registration
- Implementation of input information validators during php Registration
- The php user registration page uses js for form verification of specific instances
- A complete example of ThinkPHP user registration Logon Message
- PHP + jQuery registration module development details
- PHP + jQuery registration module improvement (2): Mailbox Activation
- WAMPserver configuration method (allow external access, and set phpmyadmin to enter the user name and password for Logon)