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 = "
  successfully registered !
"; }else { $message_result = "
  error while registering !
"; } } else { $message_result = "
  sorry live_user_email already taken !
"; } $Db_connect->close(); } ?> Simple Login and Signup System using PHP and MySQLi | Login & Registration System

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 = "
Invalid live_user_name or live_user_pass !
"; } $Db_connect->close(); } ?> live 24 u - Login & Registration System

dashboard.php

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

?>



Welcome - 

 
 







live 24 u - Programming Blog

Tutorials on PHP,Angularjs, MySQL,Vuejs, Ajax, jQuery, Web Design or web developemnt and more...

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");
}

Leave a Comment