Mini Shell
| Direktori : /home/mhcadmin/www/ |
|
|
| Current File : /home/mhcadmin/www/authenticate.php |
<?php
require_once 'config/config.php';
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
$username = filter_input(INPUT_POST, 'username');
$passwd = filter_input(INPUT_POST, 'passwd');
$remember = filter_input(INPUT_POST, 'remember');
$passwd= md5($passwd);
//Get DB instance. function is defined in config.php
$db = getDbInstance();
$db->where ("user_name", $username);
$db->where ("passwd", $passwd);
$row = $db->get('admin_accounts');
if ($db->count >= 1) {
$_SESSION['user_logged_in'] = TRUE;
$_SESSION['admin_type'] = $row[0]['admin_type'];
$_SESSION['Full_Name'] = $row[0] ['Full_Name'];
$_SESSION['id'] = $row[0] ['id'];
$_SESSION['UserAccessName'] = $row[0]['UserAccessName'];
$_SESSION['Region'] = $row[0]['Region'];
if ($_SESSION['UserAccessName'] === 'Administrator'){
header('Location:AdminPortal.php');
exit;}
else if ($_SESSION['UserAccessName'] === 'Client'){
header('Location:Portal.php');
exit;}
if($remember)
{
setcookie('username',$username , time() + (86400 * 90), "/");
setcookie('password',$passwd , time() + (86400 * 90), "/");
}
if ($_SESSION['UserAccessName'] = 'Administrator'){
header('Location:AdminPortal.php');
exit;}
else if ($_SESSION['UserAccessName'] = 'Client'){
header('Location:Portal.php');
exit;}
} else {
$_SESSION['failure'] = "Invalid user name or password";
header('Location:In73nal_Login.php');
exit;
}
}?>