Dear Mates, Please click the ads to support us.

Enable Disable User Login in PHP

Kailash Singh

Enable Disable User Login in PHP

Published Mar 25,2022 by Kailash Singh

0 Comment     9136 Views    


In this tutorial, we are going to teach you. How to create Enable Disable User Login in PHP.

This tutorial gives the information of the user, if their account has been disabled by the administrator(admin). The admin side is the only one can manage the account of every users to enable or disable it. And this is code of PHP, Bootsrap and MySQLi, this programs are written in a way that any one can understand and customize for their projects.

 

Step 1 : Create login User table and insert some users detail in table.

INSERT INTO `elevenstech_login_user` (`id`, `name`, `mobile`, `email`, `password`, `status`) VALUES (NULL, 'Amit Singh', '8786386833', '[email protected]', '12345678', '0'), (NULL, 'Kailash Singh', '9939999999', '[email protected]', '12345678', '1');

 

Step 2: Create connection.php file for connectivity to Database and PHP.

<?php 
    
	$con = mysqli_connect('localhost','root','','elevenstech');

?>

 

Step3: Create Login page for user.

<?php 

  //when you start work on login. Firstly start session.
  session_start();

  //include connection file here
  include('connection.php');

  //here i am checking. User logged in or not.
  if(!empty($_SESSION['login_id']))
  {
      header("location:welcome.php");
  }

  $error = '';  //Initialize error variable

  if(isset($_POST['submit'])) 
  {

      $email = $_POST['email'];
      $password = $_POST['password']; 

      //check query for user and password exist in user table or not
      $sql = "SELECT * FROM elevenstech_login_user WHERE email = '$email' and password = '$password'";

      $row = mysqli_query($con,$sql);
      $count = mysqli_num_rows($row);

      if($count > 0)
      {

          //Here I am fetching user detail
          $rows = mysqli_fetch_object($row);

          // Here I am checking user login enable or disable.. if user status is 1. So it will redirect to welcome page otherwise show error message.
          if($rows->status == '1')
          {
              $_SESSION['login_id'] = $rows->id;
              $_SESSION['login_name'] = $rows->name;
              $_SESSION['login_email'] = $rows->email;
              header("location: welcome.php");
          }
          else
          {
              $error = "You don't have permission to login";
          }
          
      }
      else 
      {
          $error = "Your Login email or Password is invalid";
      }
      
   }

?>

<form id="login-form" class="form" action="" method="post">
    <h3 class="text-center text-info">Enable Disable User Login in PHP</h3>


    <div style = "text-align: center; font-size:16px; color:#cc0000; margin-top:10px"><?php echo $error; ?></div>


    <div class="form-group">
        <label for="username" class="text-info">Email:</label><br>
        <input type="text" name="email" class="form-control">
    </div>
    <div class="form-group">
        <label for="password" class="text-info">Password:</label><br>
        <input type="text" name="password" class="form-control">
    </div>
    <div class="form-group">
        <input type="submit" name="submit" class="btn btn-info btn-md" value="Login">
    </div>
</form>

 


Comments ( 0 )


SEARCH POST HERE


Support Us

Subscribe My YouTube Channel

Join Our Telegram Channel & Support Eachother

CATEGORIES

INTERVIEW QUESTIONS

PROJECT SOURCE CODE






POPULAR POSTS