Create Signup and Login PHP System

PHP Signup and login is the important part of website. so in this article we will create Singnup and login PHP system with MySQL database.

PHP language is the father website because website dynamic features are depended on PHP, using PHP you can insert, select, update and delete data from MySQL database. In this article, we will create signup and login PHP system with MySQL database signup & login system is the important parts of the website for user authentication you will use signup & login PHP system to only allow authentic users to your website. to create Signup & login PHP system follow the following steps.
login php

Follow Steps:

  1. First you need to create a database so go to phpmyadmin database and click on SQL tab and paste the below code inside SQL query area.
  2. Create Database php_crud
    
  3. Now create table inside php_crud database so for creating the table you need to copy the below code and paste the code in SQL query area
  4. 
    CREATE TABLE `signup` (
     `id` int(11) NOT NULL AUTO_INCREMENT,
     `name` varchar(50) NOT NULL,
     `email` varchar(100) NOT NULL,
     `password` varchar(255) NOT NULL,
     PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1
    
  5. Now create connection file inside a folder or create connection inside main folder as you wash but in my case i create connection file inside connection folder so create connect.php file and copy the below code and paste in your connect.php file
  6. 
    <?php 
    $db = new mysqli("localhost","root","","php_crud");
    if($db->connect_error){
     echo "Connection".$db->connect_error;
    }
     ?>
    
  7. Now create index.php file in index.php file you have the html signup form and also you have the php back-end code for signup so copy the below code and paste the code inside your index.php file
  8. 
    <?php include 'connection/connect.php';
    if(isset($_POST['signup'])){
     $name      = $_POST['name'];
     $email     = $_POST['email'];
     $password  = $_POST['password'];
     $confirm   = $_POST['confirm'];
     $reg       = "/^[a-zA-Z ]+$/";
     
     $errors    = array();
     if(empty($name)){
      $errors['name_error'] = "Name is required";
     } else if(!preg_match($reg, $name)){
      $errors['name_error'] = "Only Characters are allowed";
      $name = "";
     }
     if(empty($email)){
      $errors['email_error'] = "Email is required!";
     }else{
      $Email_check = $db->query("SELECT email FROM signup WHERE email = '$email'");
      if($Email_check->num_rows == 0){
    
      }else{
       $errors['email_error'] = "Sorry this email is already exist";
       $email = "";
      }
     }
     if(empty($password)){
      $errors['password_error'] = "Password is required";
     }else if(strlen($password) < 4){
      $errors['password_error'] = "Your password is too short";
      $password = "";
     }
     if(empty($confirm)){
      $errors['confirm_error'] = "Confirm password is required";
     }else if($confirm != $password){
      $errors['confirm_error'] = "Please confirm your password!";
      $confirm = "";
     }
     if(!empty($name) && !empty($email) && !empty($password) && !empty($confirm)){
      $password = password_hash($password,PASSWORD_DEFAULT);
      $Query = $db->query("INSERT INTO signup (name,email,password) VALUES ('$name','$email','$password')");
      if($Query){
       header("location:success.php?signup_success='Your acccount is successfully created!'");
      }else{
       echo "<script>alert('Sorry query not work')</script>";
      }
      
     }
    
    }
    
     ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
     <meta charset="UTF-8">
     <title>Create Signup && Login</title>
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
        <style type="text/css">
         ul{
          margin:0;
          padding:0;
         }
         ul li{
          margin:0;
          padding: 0;
          color:red;
          list-style: none;
         }
        </style>
    </head>
    <body>
     <nav class="navbar navbar-expand-lg navbar-light bg-light">
      <div class="container">
      <a class="navbar-brand" href="#">Singup & Login</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
    
      <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item active">
            <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
          </li>
          <li class="nav-item">
           <a href="login.php" class="nav-link">login</a>
          </li>
    
          <li class="nav-item">
           
          </li>
        </ul>
        
      </div>
    </div>
    </nav>
    <div class="container" style="margin-top: 50px;">
     <div class="row">
      <div class="col-md-5">
       <div class="card">
        <div class="card-header">
         <h3>Create Account</h3>
        </div><!-- card-header -->
        <div class="card-body">
         <form action="" method="POST">
          <div class="form-group">
           <?php 
                                if(isset($errors)): ?>
                                <?php foreach($errors as $error_show): ?>
                                 <ul>
                                  <li><?php echo $error_show; ?></li>
                                 </ul>
                                <?php endforeach; ?>
                            <?php endif; ?>
    
          </div>
          <div class="form-group">
           <input type="text" name="name" placeholder="Enter Name..." class="form-control" value="<?php if(isset($name)){ echo $name; }?>">
          </div><!-- form-group -->
          <div class="form-group">
           <input type="email" name="email" placeholder="Enter Email..." class="form-control" value="<?php if(isset($email)){ echo $email; }?>">
          </div><!-- form-group -->
          <div class="form-group">
           <input type="password" name="password" placeholder="Create Password..." class="form-control" value="<?php if(isset($password)){ echo $password; }?>">
          </div><!-- form-group -->
          <div class="form-group">
           <input type="password" name="confirm" placeholder="Confirm Password..." class="form-control" value="<?php if(isset($confirm)){ echo $confirm; }?>">
          </div><!-- form-group -->
          <div class="form-group">
           <input type="submit" name="signup" value="Create Account" class="btn btn-success btn-block">
          </div><!-- form-group -->
       </form><!-- form -->
        </div><!-- card-body -->
       </div><!-- card -->
      </div><!-- col -->
     </div><!-- row -->
    </div><!-- container -->
    </body>
    </html>
    
  9. Now you need to create success.php file what is the mean of success.php file when user account is created successfully then we will redirect user to success.php page and we will display the success message in success.php page so copy the below code and paste the code in your success.php file
  10. 
    <!DOCTYPE html>
    <html lang="en">
    <head>
     <meta charset="UTF-8">
     <title>Document</title>
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
    </head>
    <body>
     <?php 
    if(isset($_GET['signup_success'])){
     echo "<div class='alert alert-success text-center'><h1>".$_GET['signup_success']."</h1><a href='login.php'>Login</a></div>";
    }
    
    
     ?>
    </body>
    </html>
    
  11. Now create login.php page for user login when user account is created successfully after that we need to create login.php file for user login so create login.php file and paste the below code in your login.php file.
  12. 
    <?php 
    session_start();
    include 'connection/connect.php';
    if(isset($_POST['login'])){
     $email = $_POST['email'];
     $password = $_POST['password'];
     $errors = array();
     $query = $db->query("SELECT * FROM signup WHERE email = '$email'");
     if($query->num_rows == 0){
      $errors['wrong_email'] = "Enter correct email";
     }else{
      $r = $query->fetch_assoc();
      $hash_password = $r['password'];
      if(!password_verify($password, $hash_password)){
             $errors['password_wrong'] = "Your password is wrong";
      }else{
       $_SESSION['user_login'] = $email;
       header("location:home.php");
      }
     }
    }
    
     ?>
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
     <meta charset="UTF-8">
     <title>Document</title>
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
    </head>
    <body>
      <div class="container" style="margin-top: 50px;">
       <div class="row">
        <div class="col-md-4">
         <h3>Login User</h3><hr>
         <form action="" method="POST">
          <div class="form-group">
           <?php if(isset($errors)): ?>
            <?php foreach($errors as $error): ?>
             <ul>
              <li>
               <?php echo $error; ?>
              </li>
             </ul>
            <?php endforeach; ?>
           <?php endif; ?>
          </div>
          <div class="form-group">
           <input type="email" name="email" placeholder ="Enter email..." class="form-control" required="">
          </div>
          <div class="form-group">
           <input type="password" name="password" placeholder ="Enter Password..." class="form-control" required="">
          </div>
          <div class="form-group">
           <input type="submit" name="login" value="Login" class="btn btn-success">
          </div>
         </form>
        </div>
       </div>
      </div>
    </body>
    </html>
    
  13. after user login we need to create home.php file to redirect authentic user to home.php page, so create home.php file and copy the below code and paste the below code in your home.php page.
  14. 
    <?php 
    session_start();
    if(isset($_SESSION['user_login']))
    {
    echo "<h1>Welcome user</h1><a href='logout.php'>logout</a>";
    }else{
     header("location:login.php");
    }
    
    
     ?>
    
  15. Finally you need to create logout.php file what basically do logout.php file when user click on logout link then we will redirect user to logout.php file and there we will destroy the user session so create logout.php file and copy the below code and paste the below code in your logout.php file.
  16. 
    <?php 
    session_start();
    session_destroy();
    header("location:login.php");
    
     ?>
    
Download full source code with SQL database.

[Download full souce code ##download##]

Summary:

This was the complete code guide and along with download script. so signup and login php is the most important parts of website if you have any issue in code you can feel free ask me the question in the comment area thank you.

COMMENTS

Name

bootstrap,1,CSS,6,Example,3,HTML,6,login,1,mysql,3,PHP,5,
ltr
item
webtipstricks: Create Signup and Login PHP System
Create Signup and Login PHP System
PHP Signup and login is the important part of website. so in this article we will create Singnup and login PHP system with MySQL database.
https://3.bp.blogspot.com/-mzTn6FfrFwg/Wf6naVMlS_I/AAAAAAAABbw/jgvyGiMdWt4OcR-Y_eJcAdrcPkMpMFHZACLcBGAs/s640/login-php.jpg
https://3.bp.blogspot.com/-mzTn6FfrFwg/Wf6naVMlS_I/AAAAAAAABbw/jgvyGiMdWt4OcR-Y_eJcAdrcPkMpMFHZACLcBGAs/s72-c/login-php.jpg
webtipstricks
http://www.webtipstricks.com/2017/11/signup-login-php.html
http://www.webtipstricks.com/
http://www.webtipstricks.com/
http://www.webtipstricks.com/2017/11/signup-login-php.html
true
4027471107773963481
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy