PHP Registration Login System (i)-minimalist

Source: Internet
Author: User
Tags php database

Order

Login registration system is the most common daily Internet operation, I have set up a classification of a step-by-step Perfect Registration Login system, if there is a mistake please teach

Language used: PHP

Database: MySQL

This implementation function:

1. User Registration

2. User Login

Main documents:

1 SQL creates a user table in an existing database, Id,username,password three fields

1 CREATE TABLE username (2     int (  auto_increment,3     username varchar (), 4     Password varchar (+),5    primary key (ID)6 );

2 connect.php Database configuration file

1<?PHP2$server ="localhost";//Host3$db _username="Root";//Database user name4$db _password="";//Database Password5 6$con = mysql_connect ($server, $db _username, $db _password);//Link Database7     if(!$con) {8Die"can ' t connect". Mysql_error ());//output error if link fails9     }Ten      Onemysql_select_db ('DB', $con);//Select the database (mine is test) A?>

3 signup.html Registration Form

1<!doctype html>2"en">34<meta charset="UTF-8">5<title> User Registration Page </title>67<body>8<form action="signup.php"Method="Post">9<p> User name: <input type="text"Name="name"></p>Ten<p> Password: <input type="text"Name="Password"></p> One<p><input type="Submit"Name="Submit"Value="Register"></p> A</form> -</body> -

4 signup.php Registration procedure

1<?PHP2Header"content-type:text/html; Charset=utf8");3 4     if(!isset ($_post['Submit'])){5Exit"Error Execution");6}//determine if there is a submit action7 8$name =$_post['name'];//Post Gets the name in the form9$password =$_post['Password'];//post get password in the formTen  OneInclude'connect.php');//Link Database A$q ="INSERT into username (Id,username,password) VALUES (', ' $name ', ' $password ')";//SQL to insert values from a form to a database -$reslut =mysql_query ($q, $con);//Execute SQL -      the     if(!$reslut) { -Die'Error:'. Mysql_error ());//if the SQL execution fails output error -}Else{ -Echo"Registration Successful";//Successful output registration succeeded +     } -  +Mysql_close ($con);//Close the database A  at?>

The registration process is complete, the following is the user login

5 login.html Login Form

1<!doctype html>2"en">34<meta charset="UTF-8">5<title> Login </title>67<body>8<form name="Login"action="login.php"Method="Post">9<p> User name <input type=text name="name"></p>Ten<p> Password <input type=password name="Password"></p> One<p><input type="Submit"Name="Submit"Value="Login"></p> A</form> -</body> -

6 login.php Login Program

1<?PHP2Header"content-type:text/html; Charset=utf8");3     if(!isset ($_post["Submit"])){4Exit"Error Execution");5}//detect if a submit operation is available6 7Include'connect.php');//Link Database8$name = $_post['name'];//Post get user name form value9$PASSOWRD = $_post['Password'];//Post get user password single valueTen  One     if($name && $PASSOWRD) {//if the user name and password are not empty A$sql ="SELECT * FROM username where username = ' $name ' and password= ' $PASSOWRD '";//detects if the database has corresponding username and password SQL -$result = mysql_query ($sql);//Execute SQL -$rows =mysql_num_rows ($result);//returns a numeric value the                 if($rows) {//0 false 1 True -Header"refresh:0;url=welcome.html");//If you successfully jump to the welcome.html page -Exit//This page is closed when the jump is successful.  -}Else{ +Echo"incorrect user name or password"; -Echo" +<script> ASetTimeout (function () {window.location.href='login.html';}, +); at</script> -  -                 ";//If error using JS 1 seconds after the jump to the login page retry; -              }  -              -               in  -}Else{//if the user name or password is empty toEcho"Incomplete form filling"; +Echo" -<script> theSetTimeout (function () {window.location.href='login.html';}, +); *</script>"; $ Panax Notoginseng                      //if the error using JS 1 seconds after the jump to the login page retry; -     } the  +Mysql_close ();//Close the database A?>

7 welcome.html Login Success Jump page

1 <!doctype html> 2 "en"> 3     < Head> 4         <meta charset="UTF-8"> 5         <title > Login Success </title> 6      7     <body> 8         Welcome  9     </body> 

At this point a simple complete registration login system completed, the code is very simple does not consider verifying the robustness of security, the latter will be perfect step by step, make it powerful

PHP Registration Login System (i)-minimalist

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.