dimanche 30 mai 2021

My login form is not redirecting to the next page

The login form does not redirect to the next page"dashboard.php". All the file names are correct, I have tried several browsers and I have also tried some other solutions, but nothing has changed. I don’t know why this is happening, I don’t know what to do. I am using Php 8.0.1. Here is my login page code:

<?php
ob_start();
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
session_start();
$pageTitle = 'Login';

if (isset($_SESSION['Username'])) {
    header('Location: dashboard.php'); // Redirect To Dashboard Page
    exit();
}

include 'init.php';

// Check If User Coming From HTTP Post Request

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    $username = $_POST['user'];
    $password = $_POST['pass'];
    $hashedPass = sha1($password);
    // Check If The User Exist In Database

    $stmt = $con->prepare("SELECT 
                                UserID, Username, Password 
                            FROM 
                                users 
                            WHERE 
                                Username = ? 
                            AND 
                                Password = ? 
                            AND 
                                GroupID = 1
                            LIMIT 1");

    $stmt->execute(array($username, $hashedPass));
    $row = $stmt->fetch();
    $count = $stmt->rowCount();

    // If Count > 0 This Mean The Database Contain Record About This Username

    if ($count > 0) {
        $_SESSION['Username'] = $username; // Register Session Name
        $_SESSION['ID'] = $row['UserID']; // Register Session ID
        header('Location: dashboard.php'); // Redirect To Dashboard Page

        exit();
    }

 }
?>

<form class="login" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
    <h4 class="text-center">Admin Login</h4>
    <input class="form-control" type="text" name="user" placeholder="Username" autocomplete="off" />
    <input class="form-control" type="password" name="pass" placeholder="Password" autocomplete="new- password" />
    <input class="btn btn-primary btn-block" type="submit" value="Login" />
</form>

<?php include $tpl . 'footer.php';
ob_end_flush();
?>



Aucun commentaire:

Enregistrer un commentaire