0

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');
        }
                }

    }

?>
skk
  • 13
  • 5
  • @John Conde : first, check the post completely. I have gone through previous posts. And I have followed that. People are not here for your inappropriate downvotes. I need help that's why i posted it here. – skk Oct 09 '17 at 11:36
  • [Correct Duplicate](https://stackoverflow.com/questions/4759312/session-share-across-multiple-domains-on-same-server) – Saad Suri Oct 09 '17 at 11:41
  • Is `session_save_path()` doing anything in your script? Perhaps try without. Is all of the expected `$row` data there? General guidance is to write `session_start()` before all other lines to be safe/confident. – mickmackusa Oct 13 '17 at 04:13

0 Answers0