LuisMiguelGT LuisMiguelGT - 2 months ago 7
PHP Question

login php with permission level

I have a problem in my code. I want separate logins, I want that when a login with Rank = 1 it redirect to a page when the rank is 0 = go to another is inserted. I tried to do but I had no result because it always sends to it. It was good if any of you could give me a little help.

<?php

require_once 'config.php';

$userName = $_POST["user-name"];
$userPass = $_POST["user-pass"];
$criptSen = hash("whirlpool", $userPass);
@$rediURL = $_GET["url"];

$SQL = mysql_query("SELECT Usuario, Senha FROM utilizadores WHERE Usuario='$userName' AND Senha='$criptSen'");
$query = mysql_query($SQL);
while($row = mysql_fetch_array($query)){
$rank = $row["Rank"];
}
if(mysql_num_rows($SQL) != 0){

session_start();

$_SESSION['Usuario'] = $userName;
$_SESSION['Senha'] = $criptSen;

if($rank = 0){

header("Location: membro.php");

} elseif($rank = 1) {

header("Location: admin/index.php");

}

} else {

header("Location: index.php");

}

?>

Answer

Change

if($rank = 0){

To

if($rank == 0){

Also in the else if

And in your select you don't take the field Rank you're using in your while loop

$row["Rank"];

Change:

mysql_query("SELECT Usuario, Senha FROM...

To:

mysql_query("SELECT Usuario, Senha, Rank FROM...  

EDIT

By the way, you should NOT use mysql_ functions anymore. Those are deprecated. Use mysqli_ instead