I am trying to use role-based login authentication. but somehow it is not working properly. The session variable is not echoing as well. I have used session_start() at the top. But still, i am facing this. Can you please tell me what I have done wrong? as you can see here I have echoed sess_userrole. In my DB role column is also present and assigned roles to users. If a user is an admin it should go to vm-dashboard.php else to another page. But both the times it is redirecting to the place-order.php page.
Don't mark it as a duplicate. I have used everything described in previous posts. I need help. I don't want downvotes.First, check the post and then mark it as dupliacte.
Code:
<?php
require_once 'class.user.php';
session_start();
session_save_path();
$user_login = new USER();
if($user_login->is_logged_in()!="")
{
//$user_login->redirect('sm-dashboard.php');
}
if(isset($_POST['btn-login']))
{
$email = trim($_POST['userEmail']);
$miid = trim($_POST['mi_id']);
if($user_login->login($email,$miid))
{
session_regenerate_id();
$_SESSION['sess_user_id'] = $row['userID'];
$_SESSION['sess_userEmail'] = $row['userEmail'];
$_SESSION['sess_userrole'] = $row['role'];
echo $_SESSION['sess_userrole'];
session_write_close();
if( $_SESSION['sess_userrole'] == "admin"){
header('Location: vm-dashboard.php');
}else{
header('Location: place-order.php');
}
}
}
?>