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
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.";
}
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.
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.";
}
?>