Artificial Intelligence
Please fill the required field.

Start session


session_start(); // Include config file require_once "config.php"; // store error $errors = []; // Processing form data when form is submitted if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty(trim($_POST["username"]))) { array_push($errors, "Please enter a username."); } if (empty(trim($_POST["password"]))) { array_push($errors, "Please enter a password."); } // Check errors exist if (count($errors) == 0) { $username = $_POST["username"]; $password = $_POST["password"]; $sql = "SELECT id, username, password FROM admin WHERE username = ?"; if ($stmt = $mysqli->prepare($sql)) { // Bind variables to the prepared statement as parameters $stmt->bind_param("s", $param_username); // Set parameters $param_username = $username; // Attempt to execute the prepared statement if ($stmt->execute()) { // Store result $stmt->store_result(); // Username exists, verify password if ($stmt->num_rows == 1) { // Password already hashalg $stmt->bind_result($id, $username, $hashalg_password); if ($stmt->fetch()) { if (password_verify($password, $hashalg_password)) { // Password is correct, start a new session session_start(); // Store data in session variables $_SESSION["admin_id"] = $id; $_SESSION["username"] = $username; header("location: index.php"); } else { // Password false array_push($errors, "Wrong password."); } } } else { // Username not exists array_push($errors, "Username not exists."); } } else { array_push($errors, "Something went wrong, try again later."); } // Close statement $stmt->close(); } } // Close connection $mysqli->close(); } ?> <?php include('templates/header.php') ?> <main> <div class="container-scroller dashboard"> <div class="container-fluid page-body-wrapper full-page-wrapper"> <div class="content-wrapper auth p-0 theme-two"> <div class="row d-flex align-items-center justify-content-center"> <div class="col-lg-4 mx-auto"> <div class="auth-form-light text-left py-3 px-4 px-sm-5"> <?php if (count($errors) > 0) { ?> <div class="alert alert-danger"> <ul> <?php for ($i = 0; $i < count($errors); $i++) { ?> <li><?= $errors[$i]; ?></li> <?php } ?> </ul> </div> <?php } ?> <h4><i class="mdi mdi-alert-octagon mr-2" style="font-size: 1.5rem; margin-right: 3px;"></i>Alert Admin Login</h4> <h4 class="font-weight-light">Sign in</h4> <form class="pt-3" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post"> <div class="form-group"> <input type="text" class="form-control form-control-lg" name="username" placeholder="Username"> </div> <div class="form-group"> <input type="password" class="form-control form-control-lg" name="password" placeholder="Password"> </div> <div class="mt-3"> <input type="submit" class="btn btn-block btn-warning btn-lg font-weight-medium" value="Login"> </div> <div class="my-2"> <hr> </div> <div class="text-center"> <a href="register.php" class="btn btn-block btn-warning btn-lg font-weight-medium" style="background: #1A756E; border: #1A756E"> Register </a> </div> <div class="my-2"> <hr> </div> <!-- <div class="mt-3"> <a href="register.php" class="auth-link text-black">Do not have a account? <span class="font-weight-medium">Sign up</span></a> </div> --> </form> </div> </div> </div> </div> <!-- content-wrapper ends --> </div> <!-- page-body-wrapper ends --> </div> </main> <?php include('templates/footer.php') ?>