PHP Registration Login System Simplified version _php skills

Source: Internet
Author: User
Tags form post html page php database php programming

Login registration system is the most common daily Internet operation, I set a classification step-by-step Perfect registration system, if where wrong, please forgive me.

Languages used:php

Database:mysql

This implementation function:

1. User Registration

2. User Login

Main documents:

Complete code

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

Copy Code code as follows:
CREATE table user (id int () NOT null auto_increment,username varchar (), password varchar (), 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 Database
  if (! $con) {
    die ("Can ' t connect". Mysql_error ()) ;//If link fails output error
  }
  
  mysql_select_db (' Test ', $con);//Select Database (my test)
?>

3 signup.html Registration Form

<!doctype html>
 
 

4 signup.php Registration procedure

<?php 
  Header ("content-type:text/html; Charset=utf8 ");

  if (!isset ($_post[' submit ')) {
    exit ("Error Execution");
  } To determine if there is a submit operation

  $name =$_post[' name '];//post get the name
  $password =$_post[' password '];//in the form Post gets password

  include (' connect.php ') in the form;//linked database
  $q = INSERT INTO user (Id,username,password) VALUES (NULL, ' $name ', ' $password ')//SQL $reslut to insert the value of the form into the database
  ($q, $con);//Execute SQL
  
  if (! $reslut) {
    die ( ' Error: '. Mysql_error ())//If SQL execution fails output error
  }else{
    echo "registered successfully";//Successful output registration succeeded
  }

  

  mysql_close ($con);//Close Database

?>

Registration process complete, below is User login

5 login.html Login Form

<!doctype html>
 
 

6 login.php Login Procedure

? PHP header ("content-type:text/html;
  Charset=utf8 ");
  if (!isset ($_post["Submit")) {exit ("error Execution"); }//Check for submit operation include (' connect.php ');//link Database $name = $_post[' name '];//post get user name form value $passowrd = $_post[' password '];//post get user password Single value if ($name && $passowrd) {//if user name and password are not empty $sql = "SELECT * from user where username = ' $n Ame ' and password= ' $passowrd ';//detect whether the database has 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:0;url=welcome.html");//If successful jump
       to welcome.html page exit;
        }else{echo "username or password error";
          echo "<script> settimeout (function () {window.location.href= ' login.html ';},1000);
       </script> if the error using JS 1 seconds after the jump to the login page to try again;
        }else{//if the username or password is empty echo "form is incomplete"; echo <script> settimeout (function () {window.location.href= ' login.html ';},1000);

            </script> ";
  If the error using JS 1 seconds after the jump to the login page to try again;
 Mysql_close ();//Close Database?>

7 welcome.html Login Successful jump page

<!doctype html>
 
 

At this point a simple complete registration system is complete, the code is very simple did not consider the validation of security robustness, after the improvement.

I hope this article will help you learn about PHP programming.

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.