At login, I do session_start() and then set the following session variables:
$_SESSION['id'] = $row['id'];
$_SESSION['role'] = $row['role'];
$_SESSION['customer_id'] = $row['customer_id'];
Later, in another php I check the value of these $_SESSION variables to determine which SELECT statement will be used to access the database as follows:
$sess_cid = $_SESSION['customer_id'];
if ($_SESSION['role'] = 1) {
$sql = 'SELECT * FROM my_table';
} elseif ($_SESSION['role'] = 2) {
$sql = 'SELECT * FROM my_table WHERE id = "$sess_cid"';
} else {
echo "not authorized to access app";
}
Am I not formatting the if() properly? Everything should be set to INT value in the database.