Código PHP:
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['usuario'])) {
$loginUsername=$_POST['usuario'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "nivel";
$MM_redirectLoginSuccess = "Administrador/inicio.php";
$MM_redirectLoginSuccess2 = "Consulta/inicio.php";
$MM_redirectLoginSuccess3 = "Supervisor/inicio.php";
$MM_redirectLoginFailed = "index.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_Activos3, $Activos3);
$LoginRS__query=sprintf("SELECT usuario, clave, nivel FROM usuarios WHERE usuario=%s AND clave=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $Activos3) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = mysql_result($LoginRS,0,'nivel');
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
if($loginStrGroup==1) { header("Location: " . $MM_redirectLoginSuccess ); }//redirecciona a administrador
if($loginStrGroup==2) { header("Location: " . $MM_redirectLoginSuccess2 ); }//redirecciona a consulta
if($loginStrGroup==3) { header("Location: " . $MM_redirectLoginSuccess3 ); }//redirecciona a supervisor
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>