I have two files one is controller.php and other is model.php.
controller.php
<?php
if (isset($_POST['btn_login_user']))
{
$login_user=login_user($_POST['email'],$_POST['password']);
if ($login_user){
@$msg = '
<div class="alert text-center alert-success alert-dismissible fade show" role="alert">
You logged in!
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<script>
setTimeout(function() {
window.location.href="dash_user.php";},5000);
</script>';
}else{
@$msg = '
<div class="alert text-center alert-warning alert-dismissible fade show" role="alert">
Failed to login!
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<script>
setTimeout(function() {
window.location.href="index.php";},20000);
</script>';
}
}
in here I have model.php model.php
<?php
function login_user($email,$password)
{
global $conn;
$password = md5($password);
$sql = ("SELECT * FROM `user` WHERE `us_name`=? AND `us_pwd`=?");
$res = $conn->prepare($sql);
$res->bindValue(1, $email);
$res->bindValue(2, $password);
$res->execute();
if ($res->rowCount() >= 1) {
{
$row = $res->fetch(PDO::FETCH_ASSOC);
$userSession = array(
'us_id' => $row['us_id'],
'rul_id' => $row['rul_id'],
'us_pwd' => $row['us_pwd'],
'us_name' => $row['us_name'],
);
$_SESSION['login_user'] = $userSession;
}
return true;
}
return false;
}
?>
would you please advice me how to where and how to add condition in these files to redirect by condition, like for Admin user if logged in redirect it to ad_index.php and for Normal user if logged in then redirect it to us_index.php