PHP - SWITCH

 
Vista:

SWITCH

Publicado por Mina (3 intervenciones) el 13/06/2007 18:31:21
Hola quisiera saber si es posible usar un switch para que la pagina de login me mande a diferentes paginas segun el nivel de acceso. Por ejemplo nivel 1 me manda a menu1.php y nivel 2 a menu2.php
Este es parte del codigo

if (isset($_POST['Nombre'])) {
$loginUsername=$_POST['Nombre'];
$password=$_POST['Contrasena'];
$MM_fldUserAuthorization = "nivel";
$MM_redirectLoginSuccess = "menu.php";
$MM_redirectLoginFailed = "badlogin.php";
$MM_redirecttoReferrer = false;
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:SWITCH

Publicado por basnek (63 intervenciones) el 13/06/2007 20:33:05
Efectivamente que puedes espero te sirva

*recuerda poner los Restringir Acceso a pagina que correspondan en cada caso

El codigo te quedaria algo asi:

<?php require_once('Connections/cnx.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?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['clave'];
$MM_fldUserAuthorization = "nivel";
$MM_redirectLoginSuccess = "login.php";
$MM_redirectLoginFailed = "lwp01.php";
$MM_redirecttoReferrer = true;
mysql_select_db($database_cnx, $cnx);

$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, $cnx) 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']) && true) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
// Aca interceptas
switch ($loginStrGroup) {
case "admin":
$MM_redirectLoginSuccess="menu1.php";
break;
case "user":
$MM_redirectLoginSuccess="menu2.php";
break;
case "dataentry":
$MM_redirectLoginSuccess="menu3.php";
break;
}

header("Location: " . $MM_redirectLoginSuccess );

}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
</head>

<body>
<form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
<input name="usuario" type="text" id="usuario" value="usuario" />
<input name="clave" type="text" id="clave" value="clave" />
<input type="submit" name="Submit" value="Login" />
</form>
</body>
</html>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar