Unable to get login user information in multiple php pages

前端 未结 3 2340
暖寄归人
暖寄归人 2021-01-28 22:26

I want to get user information in multiple pages so that I can show and hide the information on the basis of login user in multiple pages. Code

    

        
相关标签:
3条回答
  • 2021-01-28 22:57

    this way you can't access $role_id from anywhere accept Dashboard because you send it only dashboard. Put role_id in SESSION so that you can access from every page.

    session_start();
    if($_SESSION['login']==1){
       $_SESSION['loggedIn'] = true;  
       $_SESSION['role_id'] = $_GET['role_id'];
        header("location:api/dashboard.php");
    }
    else{
       header("location:index.php");
       echo "login unsuccessful.";
    }
    
    0 讨论(0)
  • 2021-01-28 23:09

    Once you stored role id into session. $_SESSION['role_id'] = $_GET['role_id'];

    you can get role id to the pages after login then you can hide and show some information on the following:

        <?php 
    
        session_start();
        if(!isset($_SESSION["role_id"])){
            /*..what you want to display here...*/
        }else{
            header("location:index.php");
        }
        ?>
    

    If role is not present you can redirect to index page.

    0 讨论(0)
  • 2021-01-28 23:11

    Store role_id in session if it is not changing again and again, like below:

    <?php
    session_start();
    if($_SESSION['login']==1) {
        $_SESSION['loggedIn'] = true;  
        $role_id = $_GET['role_id'];
        // store here in session
        $_SESSION['roleid'] = $role_id;
        header("location:api/dashboard.php?role_id=$role_id");
    } else {
        header("location:index.php");
        echo "login unsuccessful.";
    }
    ?>
    
    0 讨论(0)
提交回复
热议问题