Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/08/2009, 08:53
dasa
 
Fecha de Ingreso: marzo-2009
Mensajes: 132
Antigüedad: 15 años, 1 mes
Puntos: 8
Identificacion de Usuarios por Niveles

Hola, necesito una manito con esto:Tengo en mi BD una tabla usuario, donde tiene sus campos y uno que se llama rango o roll, el cual me indica quien es Administrador(A) y Usuario(U).Cree la pagina de login y su respectiva autentificacion de usuarios por nievel (rango o roll), pero necesito que si entra A me envie a la pagina administradores y si entra U me envie a usuarios.Alguna explicación o ayuda.

De antemano muchas gracias.

Añado el codigo de las dos paginas.

identificacion.php

Código PHP:
 <?php require_once('Connections/pdcsls.php'); ?>
<?php
if (isset($_POST['CLAVE'])) {$_POST['CLAVE'] = sha1($_POST['CLAVE']);}
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['login'])) {
  
$loginUsername=$_POST['login'];
  
$password=$_POST['clave'];
  
$MM_fldUserAuthorization "roll";
  
$MM_redirectLoginSuccess "administradores.php";
  
$MM_redirectLoginFailed "prueba.php";
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_pdcsls$pdcsls);
      
  
$LoginRS__query=sprintf("SELECT LOGIN, CLAVE, roll FROM usuario WHERE LOGIN=%s AND CLAVE=%s",
  
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text")); 
   
  
$LoginRS mysql_query($LoginRS__query$pdcsls) or die(mysql_error());
  
$loginFoundUser mysql_num_rows($LoginRS);
  if (
$loginFoundUser) {
    
    
$loginStrGroup  mysql_result($LoginRS,0,'roll');
    
    
//declare two session variables and assign them
    
$_SESSION['MM_Username'] = $loginUsername;
    
$_SESSION['MM_UserGroup'] = $loginStrGroup;          

    if (isset(
$_SESSION['PrevUrl']) && false) {
      
$MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
    }
    
header("Location: " $MM_redirectLoginSuccess );
  }
  else {
    
header("Location: "$MM_redirectLoginFailed );
  }
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Identificación de Usuarios</title>
<link href="CSS/Estilo.css" rel="stylesheet" type="text/css" />

</head>

<body>
<div align="center" class="LetraAzul">IDENTIFIQUESE</div>
<p>&nbsp;</p>
<form ACTION="<?php echo $loginFormAction?>" id="form1" name="form1" method="POST">
  <p>&nbsp;</p>
  <p class="alingvertical"><strong>USUARIO </strong>
    <label for="login"> </label>
    <input type="text" name="login" id="login" />
  </p>
  <p class="alingvertical"><strong>CONTRASEÑA</strong> 
    <label for="clave"></label>
    <input type="password" name="clave" id="clave" />
  </p>
  <p class="alingvertical">
    <label for="enviar"></label>
    <input name="enviar" type="submit" id="enviar" onclick="MM_validateForm('login','','R','clave','','R');return document.MM_returnValue" value="Identiquese!!" />
  </p>
  <p>&nbsp;</p>
</form>
<p>&nbsp;</p>
</body>
</html>
administradores.php

Código PHP:
 <?php require_once('Connections/pdcsls.php'); ?><?php
//initialize the session
if (!isset($_SESSION)) {
  
session_start();
}

// ** Logout the current user. **
$logoutAction $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset(
$_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  
$logoutAction .="&"htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  
//to fully log out a visitor we need to clear the session varialbles
  
$_SESSION['MM_Username'] = NULL;
  
$_SESSION['MM_UserGroup'] = NULL;
  
$_SESSION['PrevUrl'] = NULL;
  unset(
$_SESSION['MM_Username']);
  unset(
$_SESSION['MM_UserGroup']);
  unset(
$_SESSION['PrevUrl']);
    
  
$logoutGoTo "identificacion.php";
  if (
$logoutGoTo) {
    
header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  
session_start();
}
$MM_authorizedUsers "A,U";
$MM_donotCheckaccess "false";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers$strGroups$UserName$UserGroup) { 
  
// For security, start by assuming the visitor is NOT authorized. 
  
$isValid False

  
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  
if (!empty($UserName)) { 
    
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    
$arrUsers Explode(","$strUsers); 
    
$arrGroups Explode(","$strGroups); 
    if (
in_array($UserName$arrUsers)) { 
      
$isValid true
    } 
    
// Or, you may restrict access to only certain users based on their username. 
    
if (in_array($UserGroup$arrGroups)) { 
      
$isValid true
    } 
    if ((
$strUsers == "") && false) { 
      
$isValid true
    } 
  } 
  return 
$isValid
}

$MM_restrictGoTo "prueba.php";
if (!((isset(
$_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers$_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  
$MM_qsChar "?";
  
$MM_referrer $_SERVER['PHP_SELF'];
  if (
strpos($MM_restrictGoTo"?")) $MM_qsChar "&";
  if (isset(
$QUERY_STRING) && strlen($QUERY_STRING) > 0
  
$MM_referrer .= "?" $QUERY_STRING;
  
$MM_restrictGoTo $MM_restrictGoTo$MM_qsChar "accesscheck=" urlencode($MM_referrer);
  
header("Location: "$MM_restrictGoTo); 
  exit;
}
?>
<?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;
}
}

$colname_usuarios "-1";
if (isset(
$_SESSION['MM_Username'])) {
  
$colname_usuarios $_SESSION['MM_Username'];
}
mysql_select_db($database_pdcsls$pdcsls);
$query_usuarios sprintf("SELECT NOMBRE1, NOMBRE2, APELLIDO1, APELLIDO2 FROM usuario WHERE LOGIN = %s"GetSQLValueString($colname_usuarios"text"));
$usuarios mysql_query($query_usuarios$pdcsls) or die(mysql_error());
$row_usuarios mysql_fetch_assoc($usuarios);
$totalRows_usuarios mysql_num_rows($usuarios);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Administradores</title>
<style type="text/css">
<!--
.Estilo2 {
    color: #0000FF
}
-->
</style>
</head>

<body>

<p>BIENVENIDO, <?php echo $row_usuarios['NOMBRE1']; ?> <?php echo $row_usuarios['NOMBRE2']; ?> <?php echo $row_usuarios['APELLIDO1']; ?> <?php echo $row_usuarios['APELLIDO2']; ?></p>
<?php if ($_SESSION['MM_UserGroup']=='A'){ ?>
<p>ADMINISTRADOR</p>
<?php } else { ?>
<p>Contenido y enlaces para Usuarios NO JODAAAAAAAAAAAAA</p>

<p>
  <?php ?>
</p>
<p>&nbsp;</p>
<p>&nbsp;<a href="<?php echo $logoutAction ?>" class="Estilo2">Desconectar</a></p>
</body>
</html>
<?php
mysql_free_result
($usuarios);
?>