Foros del Web » Programando para Internet » PHP »

problemas para mostrar nombre luego del login

Estas en el tema de problemas para mostrar nombre luego del login en el foro de PHP en Foros del Web. Hola chicos y chicas, soy nueva por aca y tengo un pequeño problema. Tengo una pagina, la cual luego de loguearse discrimina entre los atributos ...
  #1 (permalink)  
Antiguo 12/06/2012, 08:59
 
Fecha de Ingreso: junio-2012
Ubicación: En Chile :D
Mensajes: 44
Antigüedad: 11 años, 10 meses
Puntos: 0
problemas para mostrar nombre luego del login

Hola chicos y chicas, soy nueva por aca y tengo un pequeño problema.

Tengo una pagina, la cual luego de loguearse discrimina entre los atributos de usuario. Entre los 3 tipos de usuarios, el segundo me muestra una pagina con 2 iframe dentro de unas tablas, en el iframe superior llama a una pagina X donde en teoria me deberia mostrar el nombre del usuario que se logueo.

Todo lo estoy haciendo con DW CS6.

Este es la pagina que se muestra luego de ingresar, en la cual si solicito el nombre con la variable de sesion "MM_Username" me muestra todo ok.

Código 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 "index.php";
  if (
$logoutGoTo) {
    
header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  
session_start();
}
$MM_authorizedUsers "tecnico";
$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 "clientes.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(
$_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0
  
$MM_referrer .= "?" $_SERVER['QUERY_STRING'];
  
$MM_restrictGoTo $MM_restrictGoTo$MM_qsChar "accesscheck=" urlencode($MM_referrer);
  
header("Location: "$MM_restrictGoTo); 
  exit;
}
?>
<!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>
<LINK REL="Shortcut Icon" HREF="http://www.optchile.cl/icono.ico"> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<style type="text/css">
<!--
.Estilo1 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 10px;
}
-->
</style>
<?php
// onmouseover ="window.open('nada.php','seleccion');window.open('nada.php','down');"
?>
<link href="css/barralogo.css" rel="stylesheet" type="text/css" />
</head>

<body>



<span class="Estilo1">
</span><span class="Estilo1">
<table width="955" border="0" align="center">
  <tr align="center">
    <td width="145" height="59" align="center" valign="top">&nbsp;</td>
    <td width="753" align="center" valign="top"><table width="745" align="center">
      <tr>
        <td align="center" valign="middle"><iframe src="tecnico.php" name="arriba" width="745" marginwidth="0" height="50" marginheight="0" align="center" scrolling="no" frameborder="0" id="arriba">
        <div align="center">Tu navegador no soporta frames!!</div>
        </iframe></td>
      </tr>
    </table></td>
    <td width="43" valign="top"><div align="right"><a href="<?php echo $logoutAction ?>">[x]Cerrar<br />
Sesi&oacute;n&nbsp;</a></div></td>
  </tr>
  <tr align="center">
    <td colspan="3" valign="middle"><iframe src="nada.php" name="down" width="950" marginwidth="0" height="600" marginheight="0" align="center" scrolling="Auto" frameborder="0" id="down">
    <div align="center">Tu navegador no soporta frames!!</div>
    </iframe></td>
  </tr>
</table>
</span>
</body>
</html>
Y esta es la pagina tecnico.php

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;
}
}

$colname_Recordset1 "-1";
if (isset(
$_SESSION['MM_Username'])) {
  
$colname_Recordset1 $_SESSION['MM_Username'];
}
mysql_select_db($database_localhost$localhost);
$query_Recordset1 sprintf("SELECT nombre, usuario FROM usuarios WHERE usuario = %s"GetSQLValueString($colname_Recordset1"text"));
$Recordset1 mysql_query($query_Recordset1$localhost) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?>
<!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=utf-8" />
<title>Documento sin título</title>
</head>

<body>
<table width="740" align="center">
  <tr>
    <td align="center" valign="middle">Bienvenido  <?php echo $row_Recordset1['nombre']; ?> - <?php echo $row_Recordset1['usuario']; ?></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result
($Recordset1);
?>
Me podrian echar una manito porfa que estoy pegada en esto y no se que hacer :(
  #2 (permalink)  
Antiguo 12/06/2012, 09:25
Avatar de rickyper  
Fecha de Ingreso: abril-2009
Mensajes: 182
Antigüedad: 15 años
Puntos: 10
Respuesta: problemas para mostrar nombre luego del login

Que es lo que deseas estas diciendo que en tecnico.php tambien te muestre el nombre de usuario??.- Si es asi debes iniciar la session con session_start()
Asi como lo haces el el archivo anterior algo como esto
Código PHP:
Ver original
  1. if (!isset($_SESSION)) {
  2. }
__________________
www.granideamillonaria.com
  #3 (permalink)  
Antiguo 12/06/2012, 09:32
Avatar de Heiroon  
Fecha de Ingreso: junio-2010
Ubicación: Caracas, Venezuela - Por ahora...
Mensajes: 495
Antigüedad: 13 años, 11 meses
Puntos: 63
De acuerdo Respuesta: problemas para mostrar nombre luego del login

Efectivamente como dijo rickyper, debes colocar el session start(); en todas las páginas donde desees usar las variables de sesión.

Pero te recomiendo que lo incluyas una sola vez y preferiblemente de primero, para evitar problemas de headers.

Código PHP:
Ver original
  1. if (!isset($_SESSION))
  2. {
  3. }

Saludos y exito!
__________________
Gmail : [email protected]
Twitter: @heiroon

I'm back!
  #4 (permalink)  
Antiguo 12/06/2012, 09:32
 
Fecha de Ingreso: junio-2012
Ubicación: En Chile :D
Mensajes: 44
Antigüedad: 11 años, 10 meses
Puntos: 0
Respuesta: problemas para mostrar nombre luego del login

Cita:
Iniciado por rickyper Ver Mensaje
Que es lo que deseas estas diciendo que en tecnico.php tambien te muestre el nombre de usuario??.- Si es asi debes iniciar la session con session_start()
Asi como lo haces el el archivo anterior algo como esto
Código PHP:
Ver original
  1. if (!isset($_SESSION)) {
  2. }
GRACIAS!!!!! no pense que fuese tan simple
  #5 (permalink)  
Antiguo 12/06/2012, 09:35
Avatar de Heiroon  
Fecha de Ingreso: junio-2010
Ubicación: Caracas, Venezuela - Por ahora...
Mensajes: 495
Antigüedad: 13 años, 11 meses
Puntos: 63
De acuerdo Respuesta: problemas para mostrar nombre luego del login

Como observación, el session_start() debe incluirse una sola vez (lo declaras dos veces en el primer archivo) o te dara error, en este caso no lo esta haciendo, porque lo tienes dentro de una condición.

Sin embargo, no es necesario que lo tengas dos veces. Con una sola vez al inicio de cada archivo es suficiente.

Saludos!
__________________
Gmail : [email protected]
Twitter: @heiroon

I'm back!
  #6 (permalink)  
Antiguo 12/06/2012, 09:38
Avatar de rickyper  
Fecha de Ingreso: abril-2009
Mensajes: 182
Antigüedad: 15 años
Puntos: 10
Respuesta: problemas para mostrar nombre luego del login

Asi es siempre que inicies session debe ser la primera linea, normalmente se usa:
Código PHP:
Ver original
  1. <?php
  2. //el resto de tu codigo...
  3. ?>
O como es tu caso dentro de una condicion:
Código PHP:
Ver original
  1. <?php
  2.     if (!isset($_SESSION)) {
  3.       session_start();
  4. }
  5. ?>
__________________
www.granideamillonaria.com

Última edición por rickyper; 12/06/2012 a las 09:44
  #7 (permalink)  
Antiguo 12/06/2012, 11:10
 
Fecha de Ingreso: junio-2012
Ubicación: En Chile :D
Mensajes: 44
Antigüedad: 11 años, 10 meses
Puntos: 0
Respuesta: problemas para mostrar nombre luego del login

Muchas gracias a todos!... se pasaron ^^

Etiquetas: html, login, mysql, nombre, sql, tabla, 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 16:52.