File "index.php"
Full path: /home/mysamm/public_html/mysamm_login/index.php
File
size: 4.4 B
MIME-type: text/x-php; charset=us-ascii
Charset: utf-8
Download Open Edit Advanced Editor &nnbsp; Back
<?php
include("admin/includes/header.php");
$msg = '';
$msgtype = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Get form data
$username = $_POST['username_p'];
$password = $_POST['password_p'];
// Save the user (for example, into a database)
$db = new Connection();
$res = $db->QueryCount("SELECT * FROM admin_users WHERE username = '$username' and status=0");
if ($res > 0) {
$user = $db->GetRow("SELECT * FROM admin_users WHERE username = '$username' and status=0");
$storedHashedPassword = $user['password'];
// Verify the password against the hashed password stored in the database
if (password_verify($password, $storedHashedPassword)) {
// Set timezone to Asia/Kolkata
date_default_timezone_set("Asia/Kolkata");
$ip_address = $_SERVER['REMOTE_ADDR'];
$last_login = date("Y-m-d H:i:s");
$user_id = $user['id'];
$update = $db->execute("UPDATE admin_users SET ip_address = '$ip_address', last_login = '$last_login'
WHERE id = $user_id");
//print_r($row);
//die();
// Successful login, store session data
$_SESSION['name'] = $user['name'];
$_SESSION['last_login'] = $user['last_login'];
$_SESSION['user_type'] = $user['user_type'];
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $user['username'];
$_SESSION['is_login'] = true;
$msgtype = "success";
$msg = "Login successful!";
header("location:login.php");
exit();
} else {
$msgtype = "warning";
$msg = "Invalid credentials!";
}
} else {
$msgtype = "warning";
$msg = "Invalid credentials!";
}
}
?>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card" style="margin-top: 100px;">
<div class="card-header text-center">
<h3 class="card-title">Log In</h3>
</div>
<div class="card-body">
<?php if (!empty($msg)) { ?>
<div class="alert alert-<?= htmlspecialchars($msgtype) ?> text-center">
<?= htmlspecialchars($msg) ?>
</div>
<?php } ?>
<form method="post" action="">
<div class="form-group">
<label for="username">Username<span class="text-danger">*</span>:</label>
<input type="text" id="username" name="username_p" class="form-control" required>
</div>
<div class="form-group">
<label for="password">Password<span class="text-danger">*</span>:</label>
<div class="input-group">
<input type="password" id="password" name="password_p" class="form-control" required>
<div class="input-group-append">
<span class="input-group-text" onclick="togglePassword('password', 'toggleIcon')">
<i id="toggleIcon" class="fa fa-eye"></i>
</span>
</div>
</div>
</div>
<button type="submit" name="login" class="btn btn-primary btn-block">Log In</button>
<!--
<div class="text-center" style="margin-top: 10px;">
<a href="forgot_password.php">Forgot Password?</a>
</div> -->
</form>
</div>
</div>
</div>
</div>
</div>
<script>
function togglePassword(inputId, iconId) {
var input = document.getElementById(inputId);
var icon = document.getElementById(iconId);
if (input.type === "password") {
input.type = "text";
icon.classList.remove("fa-eye");
icon.classList.add("fa-eye-slash");
} else {
input.type = "password";
icon.classList.remove("fa-eye-slash");
icon.classList.add("fa-eye");
}
}
</script>