私にはアクセス権のあるページがあります。 ユーザーは'amministratore'
ユーザーしかアクセスできません。'dipendente'
ユーザーにも同じ権限を与えたいと思います。私は、ページにアクセスできるようにするには'dipendente'
ユーザーもしたいが、私は論理演算を追加した場合、それは動作しないようです論理演算子を使用したif文の中のPHP関数
function userHasRole($role) {
include 'db.inc.php';
try
{
$sql = "SELECT COUNT(*) FROM utenti
INNER JOIN utentiruoli ON utenti.id = utenteid
INNER JOIN ruoli ON ruoloid = ruoli.id
WHERE mail = :mail AND ruoli.id = :ruoloid";
$s = $pdo->prepare($sql);
$s->bindValue(':mail', $_SESSION['mail']);
$s->bindValue(':ruoloid', $role);
$s->execute();
} catch (PDOException $e) {
$error = 'Errore nella ricarca del ruolo utente.';
include 'error.html.php';
exit();
}
$row = $s->fetch();
if ($row[0] > 0) {
return TRUE;
} else {
return FALSE;
}
}
exit();
}
if(!userHasRole('amministratore')){
$error = 'Solo gli utenti registrati possono accedere a quest\'area';
include '../accessonegato.html.php';
exit();
}
:ここ
は、コントローラの作業コードであるif(!userHasRole('amministratore') || !userHasRole('dipendente')){
$error = 'Solo gli utenti registrati possono accedere a quest\'area';
include '../accessonegato.html.php';
exit();
}
誰かが私が間違っていることを教えてもらえますか?
私は、それはそれは今働いている '&&'条件ではなく、 '||' – Panther