CasperSecurity
<?php
session_start();
include'../includes/dbconnection.php';
$username = trim($_POST['username']);
$password = trim($_POST['password']);
//Through this connection DB will be not busy when 1000s of user works at a time.
$connection = new createConnection();
$connection->connect();
$query = "SELECT * FROM user WHERE user_login_id = '$username' AND password = '$password'";
$result = mysqli_query($connection->myconn, $query);
if($numrows = mysqli_num_rows($result)){
while ($user = mysqli_fetch_assoc($result)){
if($user['is_active'] != 1){
$_SESSION['ERROR_MSG'] = "You are not an Active User" ;
$connection->close();
header('location:'.$_SERVER['HTTP_REFERER']);
}else{
$_SESSION['userId'] = $user['user_id'];
//$_SESSION['ADMIN'] = $user['user_id'];
$_SESSION['userOrgUnitId'] = $user['organisation_unit_id'];
$_SESSION['userName'] = $user['user_name'];
$_SESSION['userActiveFrom'] = strtotime($user['created_on']);
$_SESSION['userActive'] = $user['is_active'];
$connection->close();
if(isset($_SESSION['ERROR_MSG'])){
unset($_SESSION['ERROR_MSG']);
}
header('location:../app/');
}
}
}else{
$_SESSION['ERROR_MSG'] = "Invalied User Name or Password";
$connection->close();
header('location:'.$_SERVER['HTTP_REFERER']);
}
?>