Hello guys  aaj  ke  is  hamare  article  mein  hum  login  and logout  krenge  php  mein  with  the  help  of  mysql  database. Sab se  hum aap  ko btaden keh  hum aaj  3  forms bnaege aik  login  ka  2 home ka  and last  logout ka . 

Login page html:-

<!DOCTYPE html>
<html lang="en">
<head>
  <title>MalerkotlaLive Admin</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="css/astyle.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
    <div class="row">
      <div class="lgn">
      <div class="card">
        <div class="card-body">
          <div class="card-title text-center text-success">ADMIN LOGIN</div>
      <div class="class="lgn">
        <form action="#" method="post" class="form-group">
         <div class="form-group">
           <input type="email" name="email" placeholder="email id" class="form-control" id="email">
</div>
<div class="form-group">
           <input type="password" name="password" placeholder="password" class="form-control" id="pass">
</div>

           <input type="submit" name="submit" value="Login" class="btn btn-success">

</div>
</div>
</form>
</div>
</div>
</div>
  </div>

</body>
</html>

Login  after  Home  page



















LOGIN.PHP:-

<?php
include 'include/connection.php';
if(isset($_SESSION["email1"]))
{
header("location:home.php");
}
?>
<?php
if(isset($_POST["submit"]))
{
  
  $qry=$conn->query("select * from login where email='".$_POST['email']."'");
if(mysqli_num_rows($qry)>0)
{
while($row=mysqli_fetch_array($qry))
{
  if($_POST['email']==$row['email'] && $_POST['password']==$row['password'])
{

  $_SESSION['email1']=$_POST['email'];
  
  print("<script>window.location='home.php';</script>");
}
}
}
}
?>

LOGOUT.PHP:-


<?php
include 'include/connection.php';
session_unset();
session_destroy();
header("location:admin_login.php?successfully logout");
?>