I have a problem with my code to separate the logins. I want when a login with Rank = 1
is entered it redirects to a page, and when Rank
is = 0
go to another page. I tried to do but I did not have a result because he always sends me to it. How do I resolve this?
<?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");
}
?>
Code to protect Internal Pages Rank = 1
@$Usuario = $_SESSION["Usuario"];
@$Rank = $_SESSION['Rank']
if(!(isset($Usuario) && isset($Senha))){
$url = explode("/", $_SERVER["REQUEST_URI"]);
header("Location: index1.php?url=$url[3]");
} else if(isset($Usuario) && isset($Senha)){
$SQL = mysql_query("SELECT Usuario, Senha FROM utilizadores WHERE Usuario='$Usuario' AND Senha='$Senha' AND Rank=1");
if(mysql_num_rows($SQL) == 0){
echo "<script>alert(\"Area Restrita\");</scrpit>";
header("Location: ../index.php");
}
}
?>