How Login system works using PHP source code

0
601

Login.php

<?php 
session_start();
include('includes/header.php');    
?>

<div class="container">

<!-- Outer Row -->
<div class="row justify-content-center">

    <div class="col-xl-10 col-lg-12 col-md-9">

        <div class="card o-hidden border-0 shadow-lg my-5">
            <div class="card-body p-0">
                <!-- Nested Row within Card Body -->
                <div class="row">
                    <div class="col-lg-6 d-none d-lg-block bg-login-image"></div>
                    <div class="col-lg-6">
                        <div class="p-5">
                            <div class="text-center">
                                <h1 class="h4 text-gray-900 mb-4">Login Details</h1>
                                <?php if(isset($_SESSION['status']) && $_SESSION['status']!='') 
                                        {
                                            echo '<h2> '.$_SESSION['status'].' <h2>';
                                            unset($_SESSION['status']);

                                        }
                                ?>
                            </div>
                            <form class="user" action="code.php" method="POST">
                                <div class="form-group">
                                    <input type="email" name="emaill" class="form-control form-control-user"
                                        id="exampleInputEmail" aria-describedby="emailHelp"
                                        placeholder="Enter Email Address...">
                                </div>
                                <div class="form-group">
                                    <input type="password" name="passwordd" class="form-control form-control-user"
                                        id="exampleInputPassword" placeholder="Password">
                                </div>
                                
                                <button type="submit" name="login_btn" class="btn btn-primary btn-user btn-block"> Login </button>

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

    </div>

</div>

</div>
<?php
    
    include('includes/scripts.php');
  ?>

Code.php


if(isset($_POST['login_btn']))
{
    $email_login =$_POST['emaill'];
    $password =$_POST['passwordd'];

    $query = "SELECT * FROM login where email='$email_login' AND password='$password' ";
    $query_run =  mysqli_query($connection, $query);
    $usertypes = mysqli_fetch_array($query_run);
    if($usertypes['usertype'] == 'admin')
 {
     $_SESSION['username'] = $email_login;
     header('location: index.php');
 }
 else if ($usertypes['usertype'] == 'user')
 {
    $_SESSION['username'] = $email_login;
    header('location: ../index.php');
 }
 else
 {
    $_SESSION['status'] = "Invalid User";
    header('location: login.php');

 }
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here