PHP Check if user is Admin
This question already has an answer here:
$row["role"] = 1
this is assignment, not comparison. Go for $row["role"] == 1
you're using the OR operator (||), the operator verifies compliance any of the 2 conditions are indicating in the IF statement, for this reason will display the message: "You are a admin!" when any of the 2 conditions is met. If you want the 2 conditions are met to show you that message must use the logical AND (&&) to verify the validity of the 2 conditions within your IF statement.
if (isset ($_SESSION ['usr_id']) && $row ["role"] = 1) { ... }
There must be 1 in session. Try again after destroy the session.
Also change the condition
FROM : <?php if (isset($_SESSION['usr_id']) || $row["role"] = 1) { ?>
TO : <?php if ((isset($_SESSION['usr_id']) && $_SESSION['usr_id'] == 1) || $row["role"] == 1) { ?>
上一篇: PHP回声如果不工作
下一篇: PHP检查用户是否是Admin