Foros del Web » Programando para Internet » PHP »

Redireccionar Usuario Registrado

Estas en el tema de Redireccionar Usuario Registrado en el foro de PHP en Foros del Web. Hola a todos por fin he podido por medio de tutoriales y el dreamweaver hacer un login de usuarios, conectandolos y toda la cosa. Ahora ...
  #1 (permalink)  
Antiguo 06/11/2007, 11:22
Avatar de davincci  
Fecha de Ingreso: enero-2005
Mensajes: 193
Antigüedad: 19 años, 3 meses
Puntos: 0
Redireccionar Usuario Registrado

Hola a todos por fin he podido por medio de tutoriales y el dreamweaver hacer un login de usuarios, conectandolos y toda la cosa. Ahora el dreaweaver trae por defecto que despues de hacer login redireccione esta persona a una pagina determinada, pero el problema esta en que hay cuatro secciones o niveles diferentes, entonces es ahi...donde no he podido dar con la gracia.

Pregunta: Como puedo hacer para que el usuario despues de logeado vaya automaticamente a la seccion que le corresponde segun su nivel?.

Esta es la tabla:

ID int(10) UNSIGNED No auto_increment
usuario varchar(45) latin1_swedish_ci No
password varchar(45) latin1_swedish_ci No
nombre varchar(45) latin1_swedish_ci No
apellido varchar(45) latin1_swedish_ci No
email varchar(45) latin1_swedish_ci No
nivel

y este el codigo en el dreamweaver:

Código PHP:
<?php require_once('../Connections/conex.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;
}
}

mysql_select_db($database_conex$conex);
$query_loginadmin "SELECT * FROM administradores";
$loginadmin mysql_query($query_loginadmin$conex) or die(mysql_error());
$row_loginadmin mysql_fetch_assoc($loginadmin);
$totalRows_loginadmin mysql_num_rows($loginadmin);
?><?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=md5($_POST['password']);
  
$MM_fldUserAuthorization "nivel";
  
$MM_redirectLoginSuccess "seccion1.php";
  
$MM_redirectLoginFailed "error.php";
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_conex$conex);
      
  
$LoginRS__query=sprintf("SELECT usuario, password, nivel FROM administradores WHERE usuario=%s AND password=%s",
  
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text")); 
   
  
$LoginRS mysql_query($LoginRS__query$conex) 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'];    
    }
    
header("Location: " $MM_redirectLoginSuccess );
  }
  else {
    
header("Location: "$MM_redirectLoginFailed );
  }
}
?>
<html>

<head>

<title>.:: Andinasoft- Colombia ::.</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<META lang=es content="Andinasoft, software educativo, software para municipios,software empresarial,venta de equipos" name=Keywords>

<META content="Andinasoft Colombia." name=Description>

<META content=worldwide name=coverage>

<META content=all name=robots>

<META content=general name=rating>

<META content="1 days" name=revisit-after>

<meta name="distribution" content="local">

</script>

<script language="JavaScript1.2">

<!--

top.window.moveTo(0,0);

if (document.all) {

top.window.resizeTo(screen.availWidth,screen.availHeight);

}

else if (document.layers||document.getElementById) {

if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){

top.window.outerHeight = screen.availHeight;

top.window.outerWidth = screen.availWidth;

}

}

//-->

</script>

<link rel="stylesheet" href="lightbox.css" type="text/css" media="screen" />

<script type="text/javascript" src="js/prototype.js"></script>

<script type="text/javascript" src="js/scriptaculous.js?load=effects"></script>

<script type="text/javascript" src="js/lightbox.js"></script>

<link href="estilo.css" rel="stylesheet" type="text/css">

<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<link href="../estilo.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.Estilo1 {font-size: 16pt}
.Estilo2 {font-weight: bold}
-->
</style>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">



<table width="837" height="462" border="0" align="center" cellpadding="0" cellspacing="0" id="principal">

    <tr>

      <td width="2" height="462" class="leftshadow"></td>

        <td width="831" height="462" valign="top" class="leftbox"><p align="center">&nbsp;</p>
          <p align="center"><span class="titulos Estilo2 Estilo1">PANEL DE ACCESO</span></p>
          <p align="center">&nbsp;</p>
          <p align="center">&nbsp;</p>
          <form name="form1" method="POST" action="<?php echo $loginFormAction?>">
            <table width="49%" align="center">
              <tr>
                <th width="28%" scope="row"><img src="imagcpan/Login.jpg" alt="Login" width="80" height="80"></th>
                <th width="28%" scope="row"><p>&nbsp;</p>
                <div align="right">Usuario:</div></th>
                <th width="72%" scope="row"><p>&nbsp;
                  </p>
                  <p>
                    <input name="usuario" type="text" id="usuario" size="45">
                  </p></th>
              </tr>
              <tr>
                <th scope="row">&nbsp;</th>
                <th scope="row"><div align="right">Contrase&ntilde;a:</div></th>
                <th scope="row"><input name="password" type="password" id="password" size="45"></th>
              </tr>
            </table>
            <p>
            <label>
            <div align="center">
            <input type="submit" name="button" id="button" value="Enviar">
            </div>
            </label>
            </p>
</form>
          <p>&nbsp;</p>
          <p align="center"><a href="../index.php"><strong>IR A PAGINA PRINCIPAL/HOME</strong></a></p>
          <p align="center">&nbsp;</p>
          <p align="center">&nbsp;</p>
      <p align="center">&nbsp;</p></td>
        <td width="4" align="center" valign="top" class="watermark">&nbsp;</td>
  </tr>
</table>

</body>

</html>
<?php
mysql_free_result
($loginadmin);
?>

Gracias a todos.
  #2 (permalink)  
Antiguo 06/11/2007, 13:39
 
Fecha de Ingreso: octubre-2006
Mensajes: 173
Antigüedad: 17 años, 6 meses
Puntos: 3
Re: Redireccionar Usuario Registrado

Esto es un poco simple y quizás necesite hacerlo mas complejo
Pero quizás te pueda funcionar y lo que puedes hacer es ver el nivel y así re diseccionarlo
Suponiendo que el nivel en la base de datos esta por numero y ha ingresado correctamente usuaria y pass ahí es donde entraría en juego el nivel para re diseccionarlo. algo así


Código PHP:
<?php
$nivel
if($nivel == 1){
header("Location: " $page1 );
}else{
if(
$nivel == 2){
header("Location: " $page2 );
}else{
if(
$nivel == 3){
header("Location: " $page3 );
}else{
if(
$nivel == 4){
header("Location: " $page4 );
}
?>
quizás esto te pueda funcionar.
__________________
¨
  #3 (permalink)  
Antiguo 06/11/2007, 14:39
Avatar de davincci  
Fecha de Ingreso: enero-2005
Mensajes: 193
Antigüedad: 19 años, 3 meses
Puntos: 0
Pregunta Re: Redireccionar Usuario Registrado

Hola toforo entiendo lo que me dices, pero he intentado de insertar esa opcion en el codigo que te muestro y no me da, que hago mal?.



Gracias.
  #4 (permalink)  
Antiguo 06/11/2007, 16:50
Avatar de Marvin
Colaborador
 
Fecha de Ingreso: febrero-2005
Ubicación: global $Chile->Santiago;
Mensajes: 1.991
Antigüedad: 19 años, 2 meses
Puntos: 81
Re: Redireccionar Usuario Registrado

Ok... segun tu code esta variable es para hacer el redirect:
Código PHP:
$MM_redirectLoginSuccess "seccion1.php"
Por lo tanto antes de asignarle el valor, haces el switch o si tus paginas son seccion1 (nivel 1), seccion 2 (nivel 2) y asi sucesivamente, lo que puedes hacer es esto:
Código PHP:
$MM_redirectLoginSuccess "seccion".$nivel.".php"
Suerte!
__________________
El que dice "Solo sé que nada sé", esta asumiendo que sabe algo.
Lea las FAQ's!
  #5 (permalink)  
Antiguo 06/11/2007, 17:03
Avatar de dopon  
Fecha de Ingreso: julio-2005
Ubicación: Cucuta / Colombia
Mensajes: 493
Antigüedad: 18 años, 9 meses
Puntos: 1
Re: Redireccionar Usuario Registrado

yo te recomendaria que por seguridad mas bien no hagas nada en ese script que ya tienes osea dejalo intacto

y en seccion1.php haces un include con la variable $_SESSION['MM_UserGroup'] quedando algo asi

Código PHP:
<?php
session_start
();
switch (
$_SESSION['MM_UserGroup']) {
  case 
1:
include(
"seccion-apta-para-nivel-1.php");break;
  case 
2:
include(
"seccion-apta-para-nivel-2.php");break;
  case 
3:
include(
"seccion-apta-para-nivel-3.php");break;
 case 
4:
include(
"seccion-apta-para-nivel-4.php");break;
}
?>
  #6 (permalink)  
Antiguo 06/11/2007, 18:00
Avatar de davincci  
Fecha de Ingreso: enero-2005
Mensajes: 193
Antigüedad: 19 años, 3 meses
Puntos: 0
Re: Redireccionar Usuario Registrado

Gracias a todos, probare las dos formas y les comento.


Saludos
  #7 (permalink)  
Antiguo 06/11/2007, 20:56
Avatar de davincci  
Fecha de Ingreso: enero-2005
Mensajes: 193
Antigüedad: 19 años, 3 meses
Puntos: 0
Exclamación Re: Redireccionar Usuario Registrado

Hola a todos,e stoy mas perdido que lombris en fiesta de gallinas.

En que parte debe ir este codigo? pues lo he introducido y me da error. Gracias.


Código PHP:
<?php
session_start
();
switch (
$_SESSION['MM_UserGroup']) {
  case 
1:
include(
"seccion-apta-para-nivel-1.php");break;
  case 
2:
include(
"seccion-apta-para-nivel-2.php");break;
  case 
3:
include(
"seccion-apta-para-nivel-3.php");break;
 case 
4:
include(
"seccion-apta-para-nivel-4.php");break;
}
?>
__________________
Mil gracias por sus enseñanzas.

Davincci
  #8 (permalink)  
Antiguo 06/11/2007, 21:13
Avatar de dopon  
Fecha de Ingreso: julio-2005
Ubicación: Cucuta / Colombia
Mensajes: 493
Antigüedad: 18 años, 9 meses
Puntos: 1
Re: Redireccionar Usuario Registrado

en el script al que redirectas
  #9 (permalink)  
Antiguo 06/11/2007, 21:24
Avatar de davincci  
Fecha de Ingreso: enero-2005
Mensajes: 193
Antigüedad: 19 años, 3 meses
Puntos: 0
De acuerdo Como que resuelto

Hola a todo al parecer esta resuelto, pues he colocado lo que me han sugerido y me ingresa como quiero, aqui dejo el codigo por que puede haber un error, me dicen si esta bien?, gracias.

Código PHP:
<?php require_once('Connections/conex.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;
}
}

mysql_select_db($database_conex$conex);
$query_menu "SELECT * FROM categorias";
$menu mysql_query($query_menu$conex) or die(mysql_error());
$row_menu mysql_fetch_assoc($menu);
$totalRows_menu mysql_num_rows($menu);
?>
<?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=md5($_POST['password']);
  
$MM_fldUserAuthorization "nivel";
  
//$MM_redirectLoginSuccess = "colegios.php";
  
$MM_redirectLoginSuccess "seccion".$nivel.".php";
session_start();
switch (
$_SESSION['MM_UserGroup']) {
  case 
1:
include(
"seccion1.php");break;
  case 
2:
include(
"seccion2.php");break;
  case 
3:
include(
"seccion3.php");break;
 }
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_conex$conex);
      
  
$LoginRS__query=sprintf("SELECT usuario, password, nivel FROM usuarios WHERE usuario=%s AND password=%s",
  
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text")); 
   
  
$LoginRS mysql_query($LoginRS__query$conex) 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'];    
    }
    
header("Location: " $MM_redirectLoginSuccess );
  }
  else {
    
header("Location: "$MM_redirectLoginFailed );
  }
}
?>
<html>

<head>

<title>PRUEBAS</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<META lang=es content="PRUEBAS" name=Keywords>

<META content="PRUEBAS" name=Description>

<META content=worldwide name=coverage>

<META content=all name=robots>

<META content=general name=rating>

<META content="1 days" name=revisit-after>

<meta name="distribution" content="local">

</script>

<script language="JavaScript1.2">

<!--

top.window.moveTo(0,0);

if (document.all) {

top.window.resizeTo(screen.availWidth,screen.availHeight);

}

else if (document.layers||document.getElementById) {

if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){

top.window.outerHeight = screen.availHeight;

top.window.outerWidth = screen.availWidth;

}

}

//-->

</script>

<link rel="stylesheet" href="lightbox.css" type="text/css" media="screen" />

<script type="text/javascript" src="js/prototype.js"></script>

<script type="text/javascript" src="js/scriptaculous.js?load=effects"></script>

<script type="text/javascript" src="js/lightbox.js"></script>

<link href="estilo.css" rel="stylesheet" type="text/css">

<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>

<style type="text/css">
<!--
.Estilo2 {
    font-size: 14px;
    color: #000000;
    font-weight: bold;
}
.Estilo3 {font-size: 10px}
a:visited {
    color: #000000;
}
a:hover {
    color: #666666;
}
a:active {
    color: #333333;
}
.Estilo7 {color: #000000}
.Estilo10 {font-size: 9pt; color: #FFFFFF; }
.Estilo12 {font-size: 12pt}
.Estilo13 {font-size: 12px; }
-->
</style>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">



<table width="571" height="768" border="0" align="center" cellpadding="0" cellspacing="0" id="principal">

    <tr>

      <td width="571" height="462" valign="top" class="content"><p align="center" class="titulos Estilo12">Registro de Clientes</p>
          <form name="form1" method="POST" action="<?php echo $loginFormAction?>">
          <table width="69%" align="center">
            <tr>
              <th width="51%" scope="row"><div align="right" class="Estilo13">Nombre de usuario:</div></th>
              <th width="49%" scope="row"><label>
                <div align="left">
                  <input name="usuario" type="text" id="usuario" size="45">
                </div>
              </label></th>
            </tr>
            <tr>
              <th scope="row"><div align="right" class="Estilo13">Password:</div></th>
              <th scope="row"><div align="left">
                <input name="password" type="password" id="password" size="45">
              </div></th>
            </tr>
          </table>
          <p>
          <label>
          <div align="center">
          <input type="submit" name="button" id="button" value="Ingresar">
          </div>
          </label>
          </p>
          </form>        <p align="center" class="titulos Estilo12">&nbsp;</p>      </td>
  </tr>
</table>



</body>

</html>
<?php
mysql_free_result
($menu);
?>
__________________
Mil gracias por sus enseñanzas.

Davincci
  #10 (permalink)  
Antiguo 06/11/2007, 21:28
Avatar de dopon  
Fecha de Ingreso: julio-2005
Ubicación: Cucuta / Colombia
Mensajes: 493
Antigüedad: 18 años, 9 meses
Puntos: 1
Re: Redireccionar Usuario Registrado

hicste una mezcla ahi bien rara pero si e sirve bien solo recuerda validar en cada pagina dependiendo del nivel que el usuario que esta viéndola si posee el nivel adecuado pues si soy de nivel 2 me puede redireccionar a nivel2.php pero quien quita que yo en la barra en vez del 2 lo cambie por 3 y wala entre como nivel 3 sin serlo por eso te puse mi opción para ocultar la ubicación real no liarse tanto y añadirle algo de seguridad
  #11 (permalink)  
Antiguo 06/11/2007, 21:36
Avatar de davincci  
Fecha de Ingreso: enero-2005
Mensajes: 193
Antigüedad: 19 años, 3 meses
Puntos: 0
Error

Celebre antes de tiempo me da error, entro cualquier cosa y sigue derecho, pero si le doy para seccion1 o seccion2 me da erro mysql, pero si es para seccion3 entra, lo peor es que si le digito cualquier cosa entra como seccion3.
__________________
Mil gracias por sus enseñanzas.

Davincci
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.
Tema Cerrado




La zona horaria es GMT -6. Ahora son las 05:46.