LuisMiguelGT LuisMiguelGT - 6 months ago 27
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.


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['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");





if($rank = 0){


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



mysql_query("SELECT Usuario, Senha FROM...


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


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