Login and Signup System using PHP MySQLi

Login and Signup System using PHP MySQLi

Today, We want to share with you Login and Signup System using PHP MySQLi.
In this post we will show you Login and Signup System using PHP MySQLi, hear for Simple User Registration & Login Script in PHP and MySQLi we will give you demo and example for implement.
In this post, we will learn about Login and Registration Script in PHP & Mysqli with an example.

Database Design

First of all to design to create a simple databse.here in this example,user_master is a table name and “live_user_id” is a AUTO_INCREMENT key genrated means uniq key.

CREATE TABLE IF NOT EXISTS `user_master` (
  `live_user_id` int(11) NOT NULL AUTO_INCREMENT,
  `live_user_name` varchar(60) NOT NULL,
  `live_user_email` varchar(60) NOT NULL,
  `live_user_pass` varchar(255) NOT NULL,
  PRIMARY KEY (`live_user_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

database_config.php

here database connetion file all the include setting to database connect file.

connect_errno) {
         die("ERROR : -> ".$Db_connect->connect_error);
     }
?>

register.php

real_escape_string($l_username);
 $live_user_email = $Db_connect->real_escape_string($live_user_email);
 $l_username = $Db_connect->real_escape_string($l_username);
 
 $hashed_live_user_pass = live_user_pass_hash($l_username, live_user_pass_DEFAULT); // this function works only in PHP current version check 5.5 or latest version
 
 $check_live_user_email = $Db_connect->query("SELECT live_user_email FROM user_master WHERE live_user_email='$live_user_email'");
 $count=$check_live_user_email->num_rows;
 
 if ($count==0) {
  
  $query = "INSERT INTO user_master(live_user_name,live_user_email,live_user_pass) VALUES('$l_username','$live_user_email','$hashed_live_user_pass')";

  if ($Db_connect->query($query)) {
   $message_result = "<div class='alert alert-success'>
      <span class='glyphicon glyphicon-info-sign'></span>   successfully registered !
     </div>";
  }else {
   $message_result = "<div class='alert alert-danger'>
      <span class='glyphicon glyphicon-info-sign'></span>   error while registering !
     </div>";
  }
  
 } else {
  
  
  $message_result = "<div class='alert alert-danger'>
     <span class='glyphicon glyphicon-info-sign'></span>   sorry live_user_email already taken !
    </div>";
   
 }
 
 $Db_connect->close();
}
?>



<title>Simple Login and Signup System using PHP and MySQLi  | Login & Registration System</title>

 





<div class="signin-form">

 <div class="container">
     
        
       <form class="form-signin" method="post" id="register-form">
      
        <h2 class="form-signin-heading">Sign Up</h2><hr />
        
        
          
        <div class="form-group">
        
        </div>
        
        <div class="form-group">
        
        <span id="check-e"></span>
        </div>
        
        <div class="form-group">
        
        </div>
        
      <hr />
        
        <div class="form-group">
            <button type="submit" class="btn btn-default" name="form-signup">
      <span class="glyphicon glyphicon-log-in"></span>   Create Account
   </button> 
            <a href="index.php" class="btn btn-default" style="float:right">Log In Here</a>
        </div> 
      
      </form>

    </div>
    
</div>



index.php

real_escape_string($live_user_email);
 $live_user_pass = $Db_connect->real_escape_string($live_user_pass);
 
 $query = $Db_connect->query("SELECT live_user_id, live_user_email, live_user_pass FROM user_master WHERE live_user_email='$live_user_email'");
 $row=$query->fetch_array();
 
 $count = $query->num_rows; 
 
 if (live_user_pass_verify($live_user_pass, $row['live_user_pass']) && $count==1) {
  $_SESSION['live_user_session'] = $row['live_user_id'];
  header("Location: dashboard.php");
 } else {
  $message_result = "<div>
     Invalid live_user_name or live_user_pass !
    </div>";
 }
 $Db_connect->close();
}
?>




<title>live 24 u - Login & Registration System</title>

 




<div class="signin-form">
 <div class="container">
       <form class="form-signin" method="post" id="login-form">
      
        <h2 class="form-signin-heading">Sign In.</h2><hr />
        
        
        <div class="form-group">
        
        <span id="check-e"></span>
        </div>
        
        <div class="form-group">
        
        </div>
       
      <hr />
     
        <div class="form-group">
            <button type="submit" class="btn btn-default" name="btn-login" id="btn-login">
      <span class="glyphicon glyphicon-log-in"></span>   Sign In
   </button> 
            <a href="register.php" class="btn btn-default" style="float:right">Sign UP Here</a>
          
        </div>  
      </form>

    </div>
    
</div>



dashboard.php

query("SELECT * FROM user_master WHERE live_user_id=".$_SESSION['live_user_session']);
$userRow=$query->fetch_array();
$Db_connect->close();

?>



<title>Welcome - </title>

 
 





<nav class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="http://www.Pakainfo.com">live 24 u</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="http://www.Pakainfo.com/2015/03/simple-login-and-signup-system-with-php.html">Back to Article</a></li>
            <li><a href="http://www.Pakainfo.com/search/label/jQuery">jQuery</a></li>
            <li><a href="http://www.Pakainfo.com/search/label/PHP">PHP</a></li>
          </ul>
          <ul class="nav navbar-nav navbar-right">
            <li><a href="#"></a></li>
            <li><a href="logout.php?logout"><span></span>Logout</a></li>
          </ul>
        </div>
      </div>
    </nav>

<div class="container">
 <a href="http://www.Pakainfo.com/">live 24 u - Programming Blog</a><br /><br />
    <p>Tutorials on PHP,Angularjs, MySQL,Vuejs, Ajax, jQuery, Web Design or web developemnt and more...</p>
</div>



logout.php

<?php
session_start();

if (!isset($_SESSION['live_user_session'])) {
 header("Location: index.php");
} else if (isset($_SESSION['live_user_session'])!="") {
 header("Location: dashboard.php");
}

if (isset($_GET['logout'])) {
 session_destroy();
 unset($_SESSION['live_user_session']);
 header("Location: index.php");
}


Related FAQ

Here are some more FAQ related to this Article:

  1.   How to Create a Wordpress Plugin in 10 Minutes Flat
  2.   Only mailables may be queued
  3.   Get python absolute value | Python abs() Function with examples
  4.   PHP Format File Size Convert KB MB GB
  5.   Simple React Hello World Example
  6.   Laravel 7 User Login Authentication From Scratch
  7.   Triangle Pattern Program In PHP
  8.   PHP Symmetric array destructuring with Associative
  9.   jQuery Form Validator Script
  10.   Controller Function using Angular Example