Foros del Web » Programando para Internet » PHP »

seleccionar pagina dependiendo del usuario registrado

Estas en el tema de seleccionar pagina dependiendo del usuario registrado en el foro de PHP en Foros del Web. Estimados, tengo hoy el siguiente caso: Tengo una pagina, la cual toma el nombre de usuario y la contraseña desde una base de datos, y ...

  #1 (permalink)  
Antiguo 16/12/2011, 09:37
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
seleccionar pagina dependiendo del usuario registrado

Estimados, tengo hoy el siguiente caso:

Tengo una pagina, la cual toma el nombre de usuario y la contraseña desde una base de datos, y da acceso a una pagina x. Con esto no hay dramas, todo ok, pero necesito que el codigo discrimine segun el atriburo que tenga cada usuario (administrador, tecnico o cliente) segun el campo de la base de datos, ya que actualmente me los envia todos a la misma pagina.

Código PHP:
<?php require_once('Connections/localhost.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$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;
}
}

mysql_select_db($database_localhost$localhost);
$query_usuarios "SELECT * FROM usuarios";
$usuarios mysql_query($query_usuarios$localhost) or die(mysql_error());
$row_usuarios mysql_fetch_assoc($usuarios);
$totalRows_usuarios mysql_num_rows($usuarios);
?>
<?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['user'])) {
  
$loginUsername=$_POST['user'];
  
$password=$_POST['pass'];
  
$MM_fldUserAuthorization "atri";
  
$MM_redirectLoginSuccess "base_plataforma.php";
  
$MM_redirectLoginFailed "error.php";
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_localhost$localhost);
      
  
$LoginRS__query=sprintf("SELECT usuario, pass, atri FROM usuarios WHERE usuario=%s AND pass=%s",
  
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text")); 
   
  
$LoginRS mysql_query($LoginRS__query$localhost) or die(mysql_error());
  
$loginFoundUser mysql_num_rows($LoginRS);
  if (
$loginFoundUser) {
    
    
$loginStrGroup  mysql_result($LoginRS,0,'atri');
    
    if (
PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    
//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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es" dir="ltr">
<head>
<LINK REL="Shortcut Icon" HREF="icono.ico">
    <title>Plataforma</title>

    <!-- Contents -->
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="es" />
    <meta http-equiv="last-modified" content="04/04/2011 12:40:32" />
    <meta http-equiv="Content-Type-Script" content="text/javascript" />
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <!-- imCustomHead -->
    <meta http-equiv="Expires" content="0" />
    <meta name="Resource-Type" content="document" />
    <meta name="Distribution" content="global" />
    <meta name="Robots" content="index, follow" />
    <meta name="Revisit-After" content="21 days" />
    <meta name="Rating" content="general" />
    <!-- Others -->
    <meta name="Generator" content="Incomedia WebSite X5 Evolution Evolution 8.0.9 - www.websitex5.com" />
    <meta http-equiv="ImageToolbar" content="False" />
    <meta name="MSSmartTagsPreventParsing" content="True" />
    
    <!-- Parent -->
    <link rel="sitemap" href="imsitemap.html" title="Mapa general del sitio" />
    <!-- Res -->
    <script type="text/javascript" src="res/x5engine.js"></script>
    <link rel="stylesheet" type="text/css" href="res/styles.css" media="screen, print" />
    <link rel="stylesheet" type="text/css" href="res/template.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="res/print.css" media="print" />
    <!--[if lt IE 7]><link rel="stylesheet" type="text/css" href="res/iebehavior.css" media="screen" /><![endif]-->
    <link rel="stylesheet" type="text/css" href="res/p003.css" media="screen, print" />
    <link rel="stylesheet" type="text/css" href="res/handheld.css" media="handheld" />
    <link rel="alternate stylesheet" title="Alto contraste - Accesibilidad" type="text/css" href="res/accessibility.css" media="screen" />

<style type="text/css">
body,td,th {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
}
</style>
</head>
<body link="#FFFFFF">
<div id="imSite">
  <table width="964" border="0">
    <tr>
      <td><img src="imagenes/logoOPT.jpg" alt="" width="200" height="85" /></td>
    <td align="right"><p><img src="imagenes/direcciones.jpg" alt="" width="250" height="106" /></p></td>
    </tr>
  </table>
  <div class="imInvisible">
  <hr />
<a href="#imGoToCont" title="Saltar el menú principal">Ir al Contenido</a>
</div>
<div id="imBody">
    <div>

<!-- Menu START -->
<a name="imGoToMenu"></a><p class="imInvisible">Menú Principal:</p>
<div id="imMnMn">
<ul>
    <li><a class="imMnItm_1" href="index.php" title=""><span class="imHidden">Presentación</span></a></li>
    <li><a class="imMnItm_2" href="noticias.html" title=""><span class="imHidden">Noticias</span></a></li>
    <li><a class="imMnItm_3" href="plataforma.php" title=""><span class="imHidden">Plataforma</span></a></li>
    <li><a class="imMnItm_5" href="contacto.html" title=""><span class="imHidden">Contacto</span></a></li>
</ul>
</div>
<!-- Menu END -->

    </div>
<hr class="imInvisible" />
<a name="imGoToCont"></a>
    <div id="imContent">

<!-- Page START -->
<h2>Plataforma</h2>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div id="imPage">
  <form id="form1" method="POST" action="<?php echo $loginFormAction?>">
    <p>&nbsp;</p>
    <table width="903" border="0">
      <tr>
        <td width="409" align="right">Usuario: </td>
        <td width="484"><label for="user2"></label>
          <input type="text" name="user" id="user2" /></td>
      </tr>
    </table>
<p>&nbsp;</p>
<p>
  <label for="user"></label>
  </p>
    <table width="904" border="0">
      <tr>
        <td width="409" align="right">Cotrase&ntilde;a</td>
        <td width="485"><label for="pass"></label>
          <input type="password" name="pass" id="pass" /></td>
      </tr>
    </table>
    <p>&nbsp;</p>
    <label for="pass"></label>
<table width="903" border="0">
  <tr>
    <td width="409" align="right"><input type="submit" name="ingreso" id="ingreso" value="Ingresar" /></td>
    <td width="71" align="center">&nbsp;</td>
    <td width="409" align="left"><input type="reset" name="restablece" id="restablece" value="Borrar datos" /></td>
  </tr>
</table>
  </form>
</div>
<p id="imFooterSiteMap"><a href="index.php" title="">Presentación</a> | <a href="noticias.html" title="">Noticias</a> | <a href="plataforma.html" title="">Plataforma</a>| <a href="contacto.html" title="">Contacto</a> | <a href="imsitemap.html" title="Mapa general del sitio">Mapa del Sitio</a></p>

    </div>
</div>
</div>
<div class="imInvisible">
<hr />
<a href="#imGoToCont" title="Leer esta página de nuevo">Regresar al contenido</a> | <a href="#imGoToMenu" title="Leer este sitio de nuevo">Regresar al menú principal</a>
</div>


<div id="imShowBoxBG" style="display: none;" onClick="imShowBoxHide()"></div>
<div id="imShowBoxContainer" style="display: none;" onClick="imShowBoxHide()"><div id="imShowBox" style="height: 200px; width: 200px;"></div></div>
<div id="imBGSound"></div>
<div id="imToolTip"><script type="text/javascript">var imt = new IMTip;</script></div>
<script type="text/javascript">imPreloadImages('res/immnu_01b.gif,res/immnu_02b.gif,res/immnu_03b.gif,res/immnu_04b.gif,res/immnu_05b.gif')</script>
</body>
</html>
<?php
mysql_free_result
($usuarios);
?>
  #2 (permalink)  
Antiguo 16/12/2011, 09:52
 
Fecha de Ingreso: diciembre-2011
Mensajes: 26
Antigüedad: 12 años, 4 meses
Puntos: 4
De acuerdo Respuesta: seleccionar pagina dependiendo del usuario registrado

Ok amigo ya se lo que sucede lo que pasa es que no estas validando si el usuario es administrador mira este cambio que hice en el php de arriba:

Código PHP:
Ver original
  1. <?php require_once('Connections/localhost.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. mysql_select_db($database_localhost, $localhost);
  35. $query_usuarios = "SELECT * FROM usuarios";
  36. $usuarios = mysql_query($query_usuarios, $localhost) or die(mysql_error());
  37. $row_usuarios = mysql_fetch_assoc($usuarios);
  38. $totalRows_usuarios = mysql_num_rows($usuarios);
  39. ?>
  40. <?php
  41. // *** Validate request to login to this site.
  42. if (!isset($_SESSION)) {
  43. }
  44.  
  45. $loginFormAction = $_SERVER['PHP_SELF'];
  46. if (isset($_GET['accesscheck'])) {
  47.   $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  48. }
  49.  
  50. if (isset($_POST['user'])) {
  51.   $loginUsername=$_POST['user'];
  52.   $password=$_POST['pass'];
  53.   $MM_fldUserAuthorization = "atri";
  54.   $MM_redirectLoginSuccess = "base_plataforma.php";
  55.   $MM_redirectLoginFailed = "error.php";
  56.   $MM_redirecttoReferrer = false;
  57.   mysql_select_db($database_localhost, $localhost);
  58.      
  59.   $LoginRS__query=sprintf("SELECT usuario, pass, atri FROM usuarios WHERE usuario=%s AND pass=%s",
  60.   GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  61.    
  62.   $LoginRS = mysql_query($LoginRS__query, $localhost) or die(mysql_error());
  63.  
  64.   $row_usuario = mysql_fetch_array ($LoginRS__query);
  65.  
  66. if ($row_usuario[atri] == "Valor del administrador") {
  67.    header ("location: pagina del administrador");
  68. } else if ($row_usuario[atri] == "Valor del usuario normal")  {
  69.    header ("location: pagina del usuario normal");
  70. } else {
  71.  header ("location: pagina de fallo de sesion");
  72. }
  73. }
  74. ?>

Última edición por JesusCova; 16/12/2011 a las 09:59
  #3 (permalink)  
Antiguo 16/12/2011, 11:54
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: seleccionar pagina dependiendo del usuario registrado

relalizo el cambio, pero me envia a la pagina de error independiente si existe o no el usuario
  #4 (permalink)  
Antiguo 16/12/2011, 12:19
Avatar de truman_truman  
Fecha de Ingreso: febrero-2010
Ubicación: /home/user
Mensajes: 1.341
Antigüedad: 14 años, 2 meses
Puntos: 177
Respuesta: seleccionar pagina dependiendo del usuario registrado

pagina de error? que error? copialo y pegalo acá
__________________
la la la
  #5 (permalink)  
Antiguo 16/12/2011, 14:10
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: seleccionar pagina dependiendo del usuario registrado

antes de nada tienes en la tabla usuarios un campo con dicho nivel donde indiques a cada usuario en que nivel esta si administrador o invitado o como tu lo guardes? si me especificas esto lo podremos resolver , faltaria saber el nombre del campo donde das el nivel y los tipos de nivel si es que lo tienes echo si no ya estas tardando en hacerlo por que si no sera imposible
  #6 (permalink)  
Antiguo 17/12/2011, 13:22
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: seleccionar pagina dependiendo del usuario registrado

asi es, los niveles son:

administrador
tecnico
cliente

estos estan en el campo "atri"
  #7 (permalink)  
Antiguo 17/12/2011, 13:28
 
Fecha de Ingreso: diciembre-2011
Mensajes: 26
Antigüedad: 12 años, 4 meses
Puntos: 4
Respuesta: seleccionar pagina dependiendo del usuario registrado

Pero error SQL? a ver que error o te redirige a la pagina de fallo xq no existe el usuario?
  #8 (permalink)  
Antiguo 17/12/2011, 13:33
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: seleccionar pagina dependiendo del usuario registrado

dime las pagina donde seas redirigir en caso de ser admnistrador tecnico o cliente

actualmente van todos a esta pagina "base_plataforma.php" indicame las paginas que yate lo estoy armando y solo me falta eso
  #9 (permalink)  
Antiguo 17/12/2011, 13:46
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: seleccionar pagina dependiendo del usuario registrado

bueno no importa te lo ice sin las paginas ya las añades tu donde se especifica, ademas te añadi session_start(); xq no lo vi por ningun lado si esque lo tienes borralo del script siguiente

Código PHP:
Ver original
  1. <?php
  2. require_once('Connections/localhost.php');
  3.  
  4. if (!function_exists("GetSQLValueString")) {
  5. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  6. {
  7.   if (PHP_VERSION < 6) {
  8.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  9.   }
  10.  
  11.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  12.  
  13.   switch ($theType) {
  14.     case "text":
  15.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  16.       break;    
  17.     case "long":
  18.     case "int":
  19.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  20.       break;
  21.     case "double":
  22.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  23.       break;
  24.     case "date":
  25.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  26.       break;
  27.     case "defined":
  28.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  29.       break;
  30.   }
  31.   return $theValue;
  32. }
  33. }
  34.  
  35. mysql_select_db($database_localhost, $localhost);
  36. $query_usuarios = "SELECT * FROM usuarios";
  37. $usuarios = mysql_query($query_usuarios, $localhost) or die(mysql_error());
  38. $row_usuarios = mysql_fetch_assoc($usuarios);
  39. $totalRows_usuarios = mysql_num_rows($usuarios);
  40.  
  41. // *** Validate request to login to this site.
  42. if (!isset($_SESSION)) {
  43. }
  44.  
  45. $loginFormAction = $_SERVER['PHP_SELF'];
  46. if (isset($_GET['accesscheck'])) {
  47.   $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  48. }
  49.  
  50. if (isset($_POST['user'])) {
  51.   $loginUsername=$_POST['user'];
  52.   $password=$_POST['pass'];
  53.   $MM_fldUserAuthorization = "atri";
  54.   $MM_redirectLoginAdmin = "AQUI LA PAGINA DE REDIRECCION DE ADMINISTRADORES";
  55.   $MM_redirectLoginTecnico = "AQUI LA PAGINA DE REDIRECCION DE TECNICOS";  
  56.   $MM_redirectLoginCliente ="AQUI LA PAGINA DE REDIRECCION DE CLIENTES";
  57.   $MM_redirectLoginFailed = "error.php";
  58.   $MM_redirecttoReferrer = false;
  59.   mysql_select_db($database_localhost, $localhost);
  60.      
  61.   $LoginRS__query=sprintf("SELECT usuario, pass, atri FROM usuarios WHERE usuario=%s AND pass=%s",
  62.   GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  63.    
  64.   $LoginRS = mysql_query($LoginRS__query, $localhost) or die(mysql_error());
  65.   $loginFoundUser = mysql_num_rows($LoginRS);
  66.   if ($loginFoundUser) {
  67.    
  68.     $loginStrGroup  = mysql_result($LoginRS,0,'atri');
  69.    
  70.     if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
  71.     //declare two session variables and assign them
  72.     $_SESSION['MM_Username'] = $loginUsername;
  73.     $_SESSION['MM_UserGroup'] = $loginStrGroup;          
  74.  
  75.  
  76.      if (isset($_SESSION['MM_UserGroup']) == 'administrador') {
  77.        
  78.           header("Location: ". $MM_redirectLoginAdmin );
  79.    
  80.     }elseif(isset($_SESSION['MM_UserGroup']) == 'tecnico'){
  81.        
  82.           header("Location: ". $MM_redirectLoginTecnico );
  83.        
  84.          }elseif(isset($_SESSION['MM_UserGroup']) == 'cliente'){
  85.              
  86.          header("Location: ". $MM_redirectLoginCliente );
  87.          
  88.          }else{  
  89.          
  90.          header("Location: ". $MM_redirectLoginFailed ); }
  91.  
  92.   }else {
  93.     header("Location: ". $MM_redirectLoginFailed );
  94.   }
  95. }
  96. ?>
  #10 (permalink)  
Antiguo 19/12/2011, 10:19
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: seleccionar pagina dependiendo del usuario registrado

Muchisimas gracias, no me conecte el fds...

vere que onda el codigo... graciasssssss....
  #11 (permalink)  
Antiguo 19/12/2011, 11:48
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: seleccionar pagina dependiendo del usuario registrado

ok ya nos cuentas q tal funciono
  #12 (permalink)  
Antiguo 19/12/2011, 11:51
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: seleccionar pagina dependiendo del usuario registrado

aqui hice una pequeña modificacion del session_start(), que estaba puesto 2 veces perdon x el fallo

Código PHP:
Ver original
  1. <?php
  2.     require_once('Connections/localhost.php');
  3.      
  4.     if (!function_exists("GetSQLValueString")) {
  5.     function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  6.     {
  7.       if (PHP_VERSION < 6) {
  8.         $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  9.       }
  10.      
  11.       $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  12.      
  13.       switch ($theType) {
  14.         case "text":
  15.           $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  16.           break;    
  17.         case "long":
  18.         case "int":
  19.           $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  20.           break;
  21.         case "double":
  22.           $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  23.           break;
  24.         case "date":
  25.           $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  26.           break;
  27.         case "defined":
  28.           $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  29.           break;
  30.       }
  31.       return $theValue;
  32.     }
  33.     }
  34.      
  35.     mysql_select_db($database_localhost, $localhost);
  36.     $query_usuarios = "SELECT * FROM usuarios";
  37.     $usuarios = mysql_query($query_usuarios, $localhost) or die(mysql_error());
  38.     $row_usuarios = mysql_fetch_assoc($usuarios);
  39.     $totalRows_usuarios = mysql_num_rows($usuarios);
  40.    
  41.      
  42.     $loginFormAction = $_SERVER['PHP_SELF'];
  43.     if (isset($_GET['accesscheck'])) {
  44.       $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  45.     }
  46.      
  47.     if (isset($_POST['user'])) {
  48.       $loginUsername=$_POST['user'];
  49.       $password=$_POST['pass'];
  50.       $MM_fldUserAuthorization = "atri";
  51.       $MM_redirectLoginAdmin = "AQUI LA PAGINA DE REDIRECCION DE ADMINISTRADORES";
  52.       $MM_redirectLoginTecnico = "AQUI LA PAGINA DE REDIRECCION DE TECNICOS";  
  53.       $MM_redirectLoginCliente ="AQUI LA PAGINA DE REDIRECCION DE CLIENTES";
  54.       $MM_redirectLoginFailed = "error.php";
  55.       $MM_redirecttoReferrer = false;
  56.       mysql_select_db($database_localhost, $localhost);
  57.          
  58.       $LoginRS__query=sprintf("SELECT usuario, pass, atri FROM usuarios WHERE usuario=%s AND pass=%s",
  59.       GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  60.        
  61.       $LoginRS = mysql_query($LoginRS__query, $localhost) or die(mysql_error());
  62.       $loginFoundUser = mysql_num_rows($LoginRS);
  63.       if ($loginFoundUser) {
  64.        
  65.         $loginStrGroup  = mysql_result($LoginRS,0,'atri');
  66.        
  67.         if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
  68.         //declare two session variables and assign them
  69.         $_SESSION['MM_Username'] = $loginUsername;
  70.         $_SESSION['MM_UserGroup'] = $loginStrGroup;          
  71.      
  72.      
  73.          if (isset($_SESSION['MM_UserGroup']) == 'administrador') {
  74.            
  75.               header("Location: ". $MM_redirectLoginAdmin );
  76.        
  77.         }elseif(isset($_SESSION['MM_UserGroup']) == 'tecnico'){
  78.            
  79.               header("Location: ". $MM_redirectLoginTecnico );
  80.            
  81.              }elseif(isset($_SESSION['MM_UserGroup']) == 'cliente'){
  82.                  
  83.              header("Location: ". $MM_redirectLoginCliente );
  84.              
  85.              }else{  
  86.              
  87.              header("Location: ". $MM_redirectLoginFailed ); }
  88.      
  89.       }else {
  90.         header("Location: ". $MM_redirectLoginFailed );
  91.       }
  92.     }
  93.     ?>
  #13 (permalink)  
Antiguo 19/12/2011, 12:10
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: seleccionar pagina dependiendo del usuario registrado

Estimado, copie el codigo que me diste dentro de la pagina, pero al validar no me reenvia se queda en la misma pagina

asi quedo el codigo:

Código PHP:
<?php require_once('Connections/localhost.php'); ?>    
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$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;
}
}

    
session_start();
    require_once(
'Connections/localhost.php');
     
    if (!
function_exists("GetSQLValueString")) {
    function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue "")
    {
      if (
PHP_VERSION 6) {
        
$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;
    }
    }
     
    
mysql_select_db($database_localhost$localhost);
$query_usuarios "SELECT * FROM usuarios";
$usuarios mysql_query($query_usuarios$localhost) or die(mysql_error());
$row_usuarios mysql_fetch_assoc($usuarios);
$totalRows_usuarios mysql_num_rows($usuarios);
     
    
// *** 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['user'])) {
      
$loginUsername=$_POST['user'];
      
$password=$_POST['pass'];
      
$MM_fldUserAuthorization "atri";
      
$MM_redirectLoginAdmin "admins.php";
      
$MM_redirectLoginTecnico "formtecopt.php";  
      
$MM_redirectLoginCliente ="AQUI LA PAGINA DE REDIRECCION DE CLIENTES";
      
$MM_redirectLoginFailed "error.php";
      
$MM_redirecttoReferrer false;
      
mysql_select_db($database_localhost$localhost);
         
      
$LoginRS__query=sprintf("SELECT usuario, pass, atri FROM usuarios WHERE usuario=%s AND pass=%s",
      
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text"));
       
      
$LoginRS mysql_query($LoginRS__query$localhost) or die(mysql_error());
      
$loginFoundUser mysql_num_rows($LoginRS);
      if (
$loginFoundUser) {
       
        
$loginStrGroup  mysql_result($LoginRS,0,'atri');
       
        if (
PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
        
//declare two session variables and assign them
        
$_SESSION['MM_Username'] = $loginUsername;
        
$_SESSION['MM_UserGroup'] = $loginStrGroup;          
     
     
         if (isset(
$_SESSION['MM_UserGroup']) == 'administrador') {
           
              
header("Location: "$MM_redirectLoginAdmin );
       
        }elseif(isset(
$_SESSION['MM_UserGroup']) == 'tecnico'){
           
              
header("Location: "$MM_redirectLoginTecnico );
           
             }elseif(isset(
$_SESSION['MM_UserGroup']) == 'cliente'){
                 
             
header("Location: "$MM_redirectLoginCliente );
             
             }else{  
             
             
header("Location: "$MM_redirectLoginFailed ); }
     
      }else {
        
header("Location: "$MM_redirectLoginFailed );
      }
    }
    
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" dir="ltr" lang="es"><head>
<link rel="Shortcut Icon" href="icono.ico">
    <title>Plataforma</title>

    <!-- Contents -->
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Language" content="es">
    <meta http-equiv="last-modified" content="04/04/2011 12:40:32">
    <meta http-equiv="Content-Type-Script" content="text/javascript">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <!-- imCustomHead -->
    <meta http-equiv="Expires" content="0">
    <meta name="Resource-Type" content="document">
    <meta name="Distribution" content="global">
    <meta name="Robots" content="index, follow">
    <meta name="Revisit-After" content="21 days">
    <meta name="Rating" content="general">
    <!-- Others -->
    <meta name="Generator" content="Incomedia WebSite X5 Evolution Evolution 8.0.9 - www.websitex5.com">
    <meta http-equiv="ImageToolbar" content="False">
    <meta name="MSSmartTagsPreventParsing" content="True">
    
    <!-- Parent -->
    <link rel="sitemap" href="imsitemap.html" title="Mapa general del sitio">
    <!-- Res -->
    <script type="text/javascript" src="res/x5engine.js"></script>
    <link rel="stylesheet" type="text/css" href="res/styles.css" media="screen, print">
    <link rel="stylesheet" type="text/css" href="res/template.css" media="screen">
    <link rel="stylesheet" type="text/css" href="res/print.css" media="print">
    <!--[if lt IE 7]><link rel="stylesheet" type="text/css" href="res/iebehavior.css" media="screen" /><![endif]-->
    <link rel="stylesheet" type="text/css" href="res/p003.css" media="screen, print">
    <link rel="stylesheet" type="text/css" href="res/handheld.css" media="handheld">
    <link rel="alternate stylesheet" title="Alto contraste - Accesibilidad" type="text/css" href="res/accessibility.css" media="screen">

<style type="text/css">
body,td,th {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
}
</style>
</head>
<body link="#FFFFFF">
<div id="imSite">
  <table width="964" border="0" align="center">
    <tbody><tr>
      <td><img src="imagenes/logoOPT.jpg" alt="" height="85" width="200"></td>
    <td align="right"><p><img src="imagenes/direcciones.jpg" alt="" height="106" width="250"></p></td>
    </tr>
  </tbody></table>
  <div class="imInvisible">
  <hr>
<a href="#imGoToCont" title="Saltar el menú principal">Ir al Contenido</a>
</div>
<div id="imBody">
    <div>

<!-- Menu START -->
<a name="imGoToMenu"></a><p class="imInvisible">Menú Principal:</p>
<div id="imMnMn">
<ul>
    <li><a class="imMnItm_1" href="index.php" title=""><span class="imHidden">Presentación</span></a></li>
    <li><a class="imMnItm_2" href="noticias.html" title=""><span class="imHidden">Noticias</span></a></li>
    <li><a class="imMnItm_3" href="plataforma.php" title=""><span class="imHidden">Plataforma</span></a></li>
    <li><a class="imMnItm_5" href="contacto.html" title=""><span class="imHidden">Contacto</span></a></li>
</ul>
</div>
<!-- Menu END -->

    </div>
<hr class="imInvisible">
<a name="imGoToCont"></a>
    <div id="imContent">

<!-- Page START -->
<h2>Plataforma</h2>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form id="form1" method="POST" action="<?php echo $loginFormAction?>">
  <table width="903" border="0">
    <tr>
      <td width="447" align="right">Ingrese su RUT: </td>
      <td width="436"><label for="user"></label>
        <input type="text" name="user" id="user" /></td>
      </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      </tr>
    <tr>
      <td align="right"><p>Ingrese su Contrase&ntilde;a:: </p></td>
      <td><label for="pass"></label>
        <input type="password" name="pass" id="pass" /></td>
      </tr>
  </table>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <table width="903" border="0">
    <tr>
      <td width="400" align="right"><input type="submit" name="ingresar" id="ingresar" value="Ingresar" /></td>
      <td width="89">&nbsp;</td>
      <td width="400"><input type="reset" name="restaurar" id="restaurar" value="Restablecer datos" /></td>
    </tr>
  </table>
  <p>&nbsp;</p>
</form>
    </div>
</div>
</div>
<div class="imInvisible">
<hr>
<a href="#imGoToCont" title="Leer esta página de nuevo">Regresar al contenido</a> | <a href="#imGoToMenu" title="Leer este sitio de nuevo">Regresar al menú principal</a>
</div>


<div id="imShowBoxBG" style="display: none;" onclick="imShowBoxHide()"></div>
<div id="imShowBoxContainer" style="display: none;" onclick="imShowBoxHide()"><div id="imShowBox" style="height: 200px; width: 200px;"></div></div>
<div id="imBGSound"></div>
<div id="imToolTip"><script type="text/javascript">var imt = new IMTip;</script></div>
<script type="text/javascript">imPreloadImages('res/immnu_01b.gif,res/immnu_02b.gif,res/immnu_03b.gif,res/immnu_04b.gif,res/immnu_05b.gif')</script>


</body></html>
<?php
mysql_free_result
($usuarios);
?>
gracias ;)
  #14 (permalink)  
Antiguo 19/12/2011, 12:14
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: seleccionar pagina dependiendo del usuario registrado

como estas accediendo como cliente??
  #15 (permalink)  
Antiguo 19/12/2011, 12:23
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: seleccionar pagina dependiendo del usuario registrado

prueba asi y me cuentas pero si accedes como cliente no te manda a ninguna pagina por que no la especificaste

Código PHP:
Ver original
  1. <?php
  2. require_once('Connections/localhost.php'); ?>    
  3. <?php
  4. if (!function_exists("GetSQLValueString")) {
  5. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  6. {
  7.   if (PHP_VERSION < 6) {
  8.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  9.   }
  10.  
  11.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  12.  
  13.   switch ($theType) {
  14.     case "text":
  15.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  16.       break;    
  17.     case "long":
  18.     case "int":
  19.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  20.       break;
  21.     case "double":
  22.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  23.       break;
  24.     case "date":
  25.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  26.       break;
  27.     case "defined":
  28.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  29.       break;
  30.   }
  31.   return $theValue;
  32. }
  33. }
  34.     require_once('Connections/localhost.php');
  35.      
  36.     if (!function_exists("GetSQLValueString")) {
  37.     function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  38.     {
  39.       if (PHP_VERSION < 6) {
  40.         $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  41.       }
  42.      
  43.       $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  44.      
  45.       switch ($theType) {
  46.         case "text":
  47.           $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  48.           break;    
  49.         case "long":
  50.         case "int":
  51.           $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  52.           break;
  53.         case "double":
  54.           $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  55.           break;
  56.         case "date":
  57.           $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  58.           break;
  59.         case "defined":
  60.           $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  61.           break;
  62.       }
  63.       return $theValue;
  64.     }
  65.     }
  66.      
  67.     mysql_select_db($database_localhost, $localhost);
  68. $query_usuarios = "SELECT * FROM usuarios";
  69. $usuarios = mysql_query($query_usuarios, $localhost) or die(mysql_error());
  70. $row_usuarios = mysql_fetch_assoc($usuarios);
  71. $totalRows_usuarios = mysql_num_rows($usuarios);
  72.      
  73.      
  74.     $loginFormAction = $_SERVER['PHP_SELF'];
  75.     if (isset($_GET['accesscheck'])) {
  76.       $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  77.     }
  78.      
  79.     if (isset($_POST['user'])) {
  80.       $loginUsername=$_POST['user'];
  81.       $password=$_POST['pass'];
  82.       $MM_fldUserAuthorization = "atri";
  83.       $MM_redirectLoginAdmin = "admins.php";
  84.       $MM_redirectLoginTecnico = "formtecopt.php";  
  85.       $MM_redirectLoginCliente ="AQUI LA PAGINA DE REDIRECCION DE CLIENTES";
  86.       $MM_redirectLoginFailed = "error.php";
  87.       $MM_redirecttoReferrer = false;
  88.       mysql_select_db($database_localhost, $localhost);
  89.          
  90.       $LoginRS__query=sprintf("SELECT usuario, pass, atri FROM usuarios WHERE usuario=%s AND pass=%s",
  91.       GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  92.        
  93.       $LoginRS = mysql_query($LoginRS__query, $localhost) or die(mysql_error());
  94.       $loginFoundUser = mysql_fetch_array($LoginRS);
  95.  
  96.       if ($loginFoundUser) {
  97.        
  98.         if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
  99.         //declare two session variables and assign them
  100.         $_SESSION['MM_Username'] = $loginUsername;
  101.         $_SESSION['MM_UserGroup'] = $loginFoundUser['atri'];        
  102.      
  103.      
  104.          if (isset($_SESSION['MM_UserGroup']) == 'administrador') {
  105.            
  106.               header("Location: ". $MM_redirectLoginAdmin );
  107.        
  108.         }elseif(isset($_SESSION['MM_UserGroup']) == 'tecnico'){
  109.            
  110.               header("Location: ". $MM_redirectLoginTecnico );
  111.            
  112.              }elseif(isset($_SESSION['MM_UserGroup']) == 'cliente'){
  113.                  
  114.              header("Location: ". $MM_redirectLoginCliente );
  115.              
  116.              }else{  
  117.              
  118.              header("Location: ". $MM_redirectLoginFailed ); }
  119.      
  120.       }else {
  121.         header("Location: ". $MM_redirectLoginFailed );
  122.       }
  123.     }
  124.     ?>
  #16 (permalink)  
Antiguo 19/12/2011, 12:41
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: seleccionar pagina dependiendo del usuario registrado

trataba de ingresar como tecnico o como admin, si cache que como cliente no ire a ninguna parte :P
  #17 (permalink)  
Antiguo 19/12/2011, 12:43
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: seleccionar pagina dependiendo del usuario registrado

as probado el ultimo codigo que te di???si no es asi pruebalo y me cuentas que paso
  #18 (permalink)  
Antiguo 19/12/2011, 12:53
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: seleccionar pagina dependiendo del usuario registrado

naps... verifique en el visor de firefox y lo que hace, tanto con el adminsitrador como con el tecnico es entrar a admins.php y cargar inmediatamente plataforma.php, sin mas...
  #19 (permalink)  
Antiguo 19/12/2011, 12:57
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: seleccionar pagina dependiendo del usuario registrado

Código PHP:
<?php require_once('Connections/localhost.php'); ?>    <?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$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;
}
}
        
mysql_select_db($database_localhost$localhost);
$query_usuarios "SELECT * FROM usuarios";
$usuarios mysql_query($query_usuarios$localhost) or die(mysql_error());
$row_usuarios mysql_fetch_assoc($usuarios);
$totalRows_usuarios mysql_num_rows($usuarios);
         
         
        
$loginFormAction $_SERVER['PHP_SELF'];
        if (isset(
$_GET['accesscheck'])) {
          
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
        }
         
        if (isset(
$_POST['user'])) {
          
$loginUsername=$_POST['user'];
          
$password=$_POST['pass'];
          
$MM_fldUserAuthorization "atri";
          
$MM_redirectLoginAdmin "admins.php";
          
$MM_redirectLoginTecnico "formtecopt.php";  
          
$MM_redirectLoginCliente ="AQUI LA PAGINA DE REDIRECCION DE CLIENTES";
          
$MM_redirectLoginFailed "error.php";
          
$MM_redirecttoReferrer false;
          
mysql_select_db($database_localhost$localhost);
             
          
$LoginRS__query=sprintf("SELECT usuario, pass, atri FROM usuarios WHERE usuario=%s AND pass=%s",
          
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text"));
           
          
$LoginRS mysql_query($LoginRS__query$localhost) or die(mysql_error());
          
$loginFoundUser mysql_fetch_array($LoginRS);
     
          if (
$loginFoundUser) {
           
            if (
PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
            
//declare two session variables and assign them
            
$_SESSION['MM_Username'] = $loginUsername;
            
$_SESSION['MM_UserGroup'] = $loginFoundUser['atri'];        
         
         
             if (isset(
$_SESSION['MM_UserGroup']) == 'administrador') {
               
                  
header("Location: "$MM_redirectLoginAdmin );
           
            }elseif(isset(
$_SESSION['MM_UserGroup']) == 'tecnico'){
               
                  
header("Location: "$MM_redirectLoginTecnico );
               
                 }elseif(isset(
$_SESSION['MM_UserGroup']) == 'cliente'){
                     
                 
header("Location: "$MM_redirectLoginCliente );
                 
                 }else{  
                 
                 
header("Location: "$MM_redirectLoginFailed ); }
         
          }else {
            
header("Location: "$MM_redirectLoginFailed );
          }
        }
        
?>
  #20 (permalink)  
Antiguo 19/12/2011, 12:58
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: seleccionar pagina dependiendo del usuario registrado

entnces si te manda a admins.php es q funciona xq de no ser asi t mandaria a error.php
ahoar el problema es por que en tecnico te manda a admins.php

ese es lo que paso o me estoy equivocando
  #21 (permalink)  
Antiguo 19/12/2011, 12:59
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: seleccionar pagina dependiendo del usuario registrado

es qu el problema que veo cuando posteas tu el codigo es que no pones session_start(); al principio de la pagina como yo te puse verifica eso
  #22 (permalink)  
Antiguo 19/12/2011, 13:01
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: seleccionar pagina dependiendo del usuario registrado

ya solucione el loop que se me producia, pero sigue sin discriminar...
  #23 (permalink)  
Antiguo 19/12/2011, 13:03
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: seleccionar pagina dependiendo del usuario registrado

ponlo asi tal cual con session_start(); si no no funcionara

Código PHP:
Ver original
  1. <?php
  2. require_once('Connections/localhost.php'); ?>    
  3. <?php
  4. if (!function_exists("GetSQLValueString")) {
  5. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  6. {
  7.   if (PHP_VERSION < 6) {
  8.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  9.   }
  10.  
  11.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  12.  
  13.   switch ($theType) {
  14.     case "text":
  15.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  16.       break;    
  17.     case "long":
  18.     case "int":
  19.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  20.       break;
  21.     case "double":
  22.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  23.       break;
  24.     case "date":
  25.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  26.       break;
  27.     case "defined":
  28.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  29.       break;
  30.   }
  31.   return $theValue;
  32. }
  33. }
  34.     require_once('Connections/localhost.php');
  35.      
  36.     if (!function_exists("GetSQLValueString")) {
  37.     function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  38.     {
  39.       if (PHP_VERSION < 6) {
  40.         $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  41.       }
  42.      
  43.       $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  44.      
  45.       switch ($theType) {
  46.         case "text":
  47.           $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  48.           break;    
  49.         case "long":
  50.         case "int":
  51.           $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  52.           break;
  53.         case "double":
  54.           $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  55.           break;
  56.         case "date":
  57.           $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  58.           break;
  59.         case "defined":
  60.           $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  61.           break;
  62.       }
  63.       return $theValue;
  64.     }
  65.     }
  66.      
  67.     mysql_select_db($database_localhost, $localhost);
  68. $query_usuarios = "SELECT * FROM usuarios";
  69. $usuarios = mysql_query($query_usuarios, $localhost) or die(mysql_error());
  70. $row_usuarios = mysql_fetch_assoc($usuarios);
  71. $totalRows_usuarios = mysql_num_rows($usuarios);
  72.      
  73.      
  74.     $loginFormAction = $_SERVER['PHP_SELF'];
  75.     if (isset($_GET['accesscheck'])) {
  76.       $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  77.     }
  78.      
  79.     if (isset($_POST['user'])) {
  80.       $loginUsername=$_POST['user'];
  81.       $password=$_POST['pass'];
  82.       $MM_fldUserAuthorization = "atri";
  83.       $MM_redirectLoginAdmin = "admins.php";
  84.       $MM_redirectLoginTecnico = "formtecopt.php";  
  85.       $MM_redirectLoginCliente ="AQUI LA PAGINA DE REDIRECCION DE CLIENTES";
  86.       $MM_redirectLoginFailed = "error.php";
  87.       $MM_redirecttoReferrer = false;
  88.       mysql_select_db($database_localhost, $localhost);
  89.          
  90.       $LoginRS__query=sprintf("SELECT usuario, pass, atri FROM usuarios WHERE usuario=%s AND pass=%s",
  91.       GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  92.        
  93.       $LoginRS = mysql_query($LoginRS__query, $localhost) or die(mysql_error());
  94.       $loginFoundUser = mysql_fetch_array($LoginRS);
  95.  
  96.       if ($loginFoundUser) {
  97.        
  98.         if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
  99.         //declare two session variables and assign them
  100.         $_SESSION['MM_Username'] = $loginUsername;
  101.         $_SESSION['MM_UserGroup'] = $loginFoundUser['atri'];        
  102.      
  103.      
  104.          if (isset($_SESSION['MM_UserGroup']) == 'administrador') {
  105.            
  106.               header("Location: ". $MM_redirectLoginAdmin );
  107.        
  108.         }elseif(isset($_SESSION['MM_UserGroup']) == 'tecnico'){
  109.            
  110.               header("Location: ". $MM_redirectLoginTecnico );
  111.            
  112.              }elseif(isset($_SESSION['MM_UserGroup']) == 'cliente'){
  113.                  
  114.              header("Location: ". $MM_redirectLoginCliente );
  115.              
  116.              }else{  
  117.              
  118.              header("Location: ". $MM_redirectLoginFailed ); }
  119.      
  120.       }else {
  121.         header("Location: ". $MM_redirectLoginFailed );
  122.       }
  123.     }
  124.     ?>
  #24 (permalink)  
Antiguo 19/12/2011, 13:07
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: seleccionar pagina dependiendo del usuario registrado

ok, copiare el codigo tal cual, sin modificar nada de nada...
  #25 (permalink)  
Antiguo 19/12/2011, 13:09
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: seleccionar pagina dependiendo del usuario registrado

si azlo asi y me cuentas tomalo ponlo tal cual

Código PHP:
Ver original
  1. <?php
  2. require_once('Connections/localhost.php');
  3.  
  4. if (!function_exists("GetSQLValueString")) {
  5. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  6. {
  7.   if (PHP_VERSION < 6) {
  8.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  9.   }
  10.  
  11.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  12.  
  13.   switch ($theType) {
  14.     case "text":
  15.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  16.       break;    
  17.     case "long":
  18.     case "int":
  19.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  20.       break;
  21.     case "double":
  22.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  23.       break;
  24.     case "date":
  25.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  26.       break;
  27.     case "defined":
  28.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  29.       break;
  30.   }
  31.   return $theValue;
  32. }
  33. }
  34.    
  35. mysql_select_db($database_localhost, $localhost);
  36. $query_usuarios = "SELECT * FROM usuarios";
  37. $usuarios = mysql_query($query_usuarios, $localhost) or die(mysql_error());
  38. $row_usuarios = mysql_fetch_assoc($usuarios);
  39. $totalRows_usuarios = mysql_num_rows($usuarios);
  40.      
  41.      
  42.     $loginFormAction = $_SERVER['PHP_SELF'];
  43.     if (isset($_GET['accesscheck'])) {
  44.       $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  45.     }
  46.      
  47.     if (isset($_POST['user'])) {
  48.       $loginUsername=$_POST['user'];
  49.       $password=$_POST['pass'];
  50.       $MM_fldUserAuthorization = "atri";
  51.       $MM_redirectLoginAdmin = "admins.php";
  52.       $MM_redirectLoginTecnico = "formtecopt.php";  
  53.       $MM_redirectLoginCliente ="AQUI LA PAGINA DE REDIRECCION DE CLIENTES";
  54.       $MM_redirectLoginFailed = "error.php";
  55.       $MM_redirecttoReferrer = false;
  56.       mysql_select_db($database_localhost, $localhost);
  57.          
  58.       $LoginRS__query=sprintf("SELECT usuario, pass, atri FROM usuarios WHERE usuario=%s AND pass=%s",
  59.       GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  60.        
  61.       $LoginRS = mysql_query($LoginRS__query, $localhost) or die(mysql_error());
  62.       $loginFoundUser = mysql_fetch_array($LoginRS);
  63.  
  64.       if ($loginFoundUser) {
  65.        
  66.         if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
  67.         //declare two session variables and assign them
  68.         $_SESSION['MM_Username'] = $loginUsername;
  69.         $_SESSION['MM_UserGroup'] = $loginFoundUser['atri'];        
  70.      
  71.      
  72.          if (isset($_SESSION['MM_UserGroup']) == 'administrador') {
  73.            
  74.               header("Location: ". $MM_redirectLoginAdmin );
  75.        
  76.         }elseif(isset($_SESSION['MM_UserGroup']) == 'tecnico'){
  77.            
  78.               header("Location: ". $MM_redirectLoginTecnico );
  79.            
  80.              }elseif(isset($_SESSION['MM_UserGroup']) == 'cliente'){
  81.                  
  82.              header("Location: ". $MM_redirectLoginCliente );
  83.              
  84.              }else{  
  85.              
  86.              header("Location: ". $MM_redirectLoginFailed ); }
  87.      
  88.       }else {
  89.         header("Location: ". $MM_redirectLoginFailed );
  90.       }
  91.     }
  92.     ?>
  #26 (permalink)  
Antiguo 19/12/2011, 13:10
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: seleccionar pagina dependiendo del usuario registrado

nada... no discrimina...
  #27 (permalink)  
Antiguo 19/12/2011, 13:13
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: seleccionar pagina dependiendo del usuario registrado

en la bd el campo atri esta escrito tal cual como administrador cliente tecnico ?? sin mayusculas ni nada todo minusculas??'

dime lo que hace al logear exactamente a donde te dirije o q pasa
  #28 (permalink)  
Antiguo 19/12/2011, 13:17
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: seleccionar pagina dependiendo del usuario registrado

esta es la db...

Código:
INSERT INTO `usuarios` (`nombre`, `usuario`, `pass`, `atri`, `pert`) VALUES
('carlos', '8xxxxxxx', 'xxxxxxxxx', 'administrador', 'opt'),
('juanita', '1xxxxxxxxxxxx', 'xxxxxxxx', 'tecnico', 'opt'),
('jorge', '2xxxxxxxxx', 'xxxxxxxx', 'cliente', 'arm'),
y lo que hace es enviarme, independiente de lo que ingrese, a admins.php
  #29 (permalink)  
Antiguo 19/12/2011, 13:21
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: seleccionar pagina dependiendo del usuario registrado

elimina todas las cookies y sessiones cierra el navegador y prueba otra vez , puede ser que al no hacer logout se haya kedado la session de admin y por eso te mande siempre a admins.php borra las cookies si tienes ccleaner pasalo

si te manda siempre a admins.php es qxq te detecta como admiistardor por una session creada por eso prueba y borra todas las cookies y si puedes haz un logout para destruir las sessiones y ya me cuentas cierra el navegador y borra todo pasa ccleanerr si tienes
  #30 (permalink)  
Antiguo 19/12/2011, 13:40
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: seleccionar pagina dependiendo del usuario registrado

realmente no se que pasa, sigue sin discriminar el codigo... limpie todo y nada....

tienes alguna otra idea del pq de esto?

Etiquetas: dependiendo, html, mysql, sql, variables, usuarios
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:30.