Foros del Web » Programando para Internet » PHP »

Error al crear variable de sesion

Estas en el tema de Error al crear variable de sesion en el foro de PHP en Foros del Web. Estoy haciendo un login en dreamweaver, y que al loguearme me lleve a una pagina donde ademas de mostrarme le nombre de usuario tambien quiero ...
  #1 (permalink)  
Antiguo 29/07/2012, 20:39
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Error al crear variable de sesion

Estoy haciendo un login en dreamweaver, y que al loguearme me lleve a una pagina donde ademas de mostrarme le nombre de usuario tambien quiero que me muestre otros datos, pero no lo he podido conseguir, me muestra errores por favor necesito de su ayuda a ver que estoy haciendo mal.

Pagina de logueo:

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;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  
session_start();
}

$loginFormAction $_SERVER['PHP_SELF'];
if (isset(
$_GET['accesscheck'])) {
  
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset(
$_POST['Usuario'])) {
  
$loginUsername=$_POST['Usuario'];
  
$password=$_POST['Password'];
  
$MM_fldUserAuthorization "Estatus";
  
$MM_redirectLoginSuccess "PanelControl/Administradores/Validar.php";
  
$MM_redirectLoginFailed "Error.php";
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_conex$conex);
      
  
$LoginRS__query=sprintf("SELECT Usuario, Password, Estatus FROM usuarios WHERE Usuario=%s AND Password=%s",
  
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text")); 
  
  
$row mysql_fetch_assoc($LoginRS);//ESTO LO PUSE A VER SI FUNCIONABA
  
$LoginRS mysql_query($LoginRS__query$conex) or die(mysql_error());
  
$loginFoundUser mysql_num_rows($LoginRS);
  if (
$loginFoundUser) {
    
    
$loginStrGroup  mysql_result($LoginRS,0,'Estatus');
    
    
//declare two session variables and assign them
    
$_SESSION['MM_Username'] = $loginUsername;
    
$_SESSION['MM_UserGroup'] = $loginStrGroup;     
    
$_SESSION['MM_Nombres'] = $row['Nombres'];
    
$_SESSION['MM_NumIngreso'] = $row['NumIngreso'];//ESTO LO NECESITO IMPLEMENTAR
    
$_SESSION['MM_UltimoIngreso'] = $row['UltimoIngreso'];//ESTO LO NECESITO IMPLEMENTAR
    
$_SESSION['MM_IngresoHora'] = $row['IngresoHora'];//ESTO LO NECESITO IMPLEMENTAR

    
if (isset($_SESSION['PrevUrl']) && false) {
      
$MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
    }
    
header("Location: " $MM_redirectLoginSuccess );
  }
  else {
    
header("Location: "$MM_redirectLoginFailed );
  }
}
?>

pagina donde voy despues de loguear:


Código PHP:
<?php
if (!isset($_SESSION)) {
  
session_start();
}

?>

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Insertar datos en MySQL</title>
<style type="text/css">
    <!--
    body {
        font-family: "Trebuchet MS", Tahoma, Arial;
        font-size: 12px;
        color: #333333;
    }
    h2 {
        font-size: 16px;
        color: #CC0000;
    }
    input, select {
        font-family: "Trebuchet MS", Tahoma, Arial;
        font-size: 11px;
        color: #666666;
    }
    -->
    </style>
</head>
<body>
<p><strong>Bienvenido:</strong>  <?php echo $_SESSION['MM_Username']; ?></p>
<p><strong>Permiso:</strong> <?php echo $_SESSION['MM_UserGroup']; ?></p>
<p><strong>Nombres:<?php echo $_SESSION['MM_Nombres']; ?></strong></p>
<p><strong>Numero ingresos:</strong><?php echo $_SESSION['MM_NumIngreso']; ?></p>
<p><strong>Dia de ultimo ingreso:</strong><?php echo $_SESSION['MM_UltimoIngreso']; ?></p>
<p><strong>Hora de Ultimo ingreso:</strong><?php echo $_SESSION['MM_IngresoHora']; ?></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
  #2 (permalink)  
Antiguo 29/07/2012, 22:09
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Error al crear variable de sesion

<?php
session_start();

if*(isset($_SESSION['MM_Username])){?>

*<!DOCTYPE*html*PUBLIC*"-//W3C//DTD*XHTML*1.0*Transitional//EN"*"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html*xmlns="http://www.w3.org/1999/xhtml">
<head>
****<meta*http-equiv="Content-Type"*content="text/html;*charset=iso-8859-1"*/>
<title>Insertar*datos*en*MySQL</title>
<style*type="text/css">
****<!--
****body*{
********font-family:*"Trebuchet*MS",*Tahoma,*Arial;
********font-size:*12px;
********color:*#333333;
****}
****h2*{
********font-size:*16px;
********color:*#CC0000;
****}
****input,*select*{
********font-family:*"Trebuchet*MS",*Tahoma,*Arial;
********font-size:*11px;
********color:*#666666;
****}
****-->
****</style>
</head>
<body>
<p><strong>Bienvenido:</strong>**<?php*echo*$_SESSION['MM_Username'];*?></p>
<p><strong>Permiso:</strong>*<?php*echo*$_SESSION['MM_UserGroup'];*?></p>
<p><strong>Nombres:<?php*echo*$_SESSION['MM_Nombres'];*?></strong></p>
<p><strong>Numero*ingresos:</strong><?php*echo*$_SESSION['MM_NumIngreso'];*?></p>
<p><strong>Dia*de*ultimo*ingreso:</strong><?php*echo*$_SESSION['MM_UltimoIngreso'];*?></p>
<p><strong>Hora*de*Ultimo*ingreso:</strong><?php*echo*$_SESSION['MM_IngresoHora'];*?></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
<?php }else{

exit('a donde cres que vas , logueate por favor.');


}
  #3 (permalink)  
Antiguo 30/07/2012, 03:36
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Error al crear variable de sesion

Gracias por tu respuesta pero me sigue maracando error, creo que el problema esta en la pagina de logueo donde declaro variables de sesion que es lo que no he podido hacer aqui:


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;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  
session_start();
}

$loginFormAction $_SERVER['PHP_SELF'];
if (isset(
$_GET['accesscheck'])) {
  
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset(
$_POST['Usuario'])) {
  
$loginUsername=$_POST['Usuario'];
  
$password=$_POST['Password'];
  
$MM_fldUserAuthorization "Estatus";
  
$MM_redirectLoginSuccess "PanelControl/Administradores/Validar.php";
  
$MM_redirectLoginFailed "Error.php";
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_conex$conex);
      
  
$LoginRS__query=sprintf("SELECT Usuario, Password, Estatus FROM usuarios WHERE Usuario=%s AND Password=%s",
  
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text")); 
  
  
$row mysql_fetch_assoc($LoginRS);//ESTO LO PUSE A VER SI FUNCIONABA
  
$LoginRS mysql_query($LoginRS__query$conex) or die(mysql_error());
  
$loginFoundUser mysql_num_rows($LoginRS);
  if (
$loginFoundUser) {
    
    
$loginStrGroup  mysql_result($LoginRS,0,'Estatus');
    
    
//declare two session variables and assign them
    
$_SESSION['MM_Username'] = $loginUsername;
    
$_SESSION['MM_UserGroup'] = $loginStrGroup;     
    
$_SESSION['MM_Nombres'] = $row['Nombres'];
    
$_SESSION['MM_NumIngreso'] = $row['NumIngreso'];//ESTO LO NECESITO IMPLEMENTAR
    
$_SESSION['MM_UltimoIngreso'] = $row['UltimoIngreso'];//ESTO LO NECESITO IMPLEMENTAR
    
$_SESSION['MM_IngresoHora'] = $row['IngresoHora'];//ESTO LO NECESITO IMPLEMENTAR

    
if (isset($_SESSION['PrevUrl']) && false) {
      
$MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
    }
    
header("Location: " $MM_redirectLoginSuccess );
  }
  else {
    
header("Location: "$MM_redirectLoginFailed );
  }
}
?>
  #4 (permalink)  
Antiguo 30/07/2012, 09:37
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Error al crear variable de sesion

en este archivo te falta session_start() al principio de la pagina , por eso te marca error en el segundo ya que si no existe sesion_start no se crean las variables de session

Para usar sesiones basadas en cookies, session_start() debe ser llamada antes de imprimir cualquier cosa en el navegador.

if (!isset($_SESSION)) {
session_start();
}

tu error anda aqui esto esta mal mo deberia ser asi. Creo que lo estas usando para verificar si esta logeado pero asi no es.

Última edición por webankenovi; 30/07/2012 a las 09:48
  #5 (permalink)  
Antiguo 30/07/2012, 09:50
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Error al crear variable de sesion

He realizado lo que me pides y por el contrario me vota mas errores, mira el codigo


Código PHP:
<?php require_once('../Connections/conex.php'); ?>
session_start();
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

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

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  
session_start();
}

$loginFormAction $_SERVER['PHP_SELF'];
if (isset(
$_GET['accesscheck'])) {
  
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset(
$_POST['Usuario'])) {
  
$loginUsername=$_POST['Usuario'];
  
$password=$_POST['Password'];
  
$MM_fldUserAuthorization "Estatus";
  
$MM_redirectLoginSuccess "PanelControl/Administradores/Validar.php";
  
$MM_redirectLoginFailed "Error.php";
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_conex$conex);
      
  
$LoginRS__query=sprintf("SELECT Usuario, Password, Estatus FROM usuarios WHERE Usuario=%s AND Password=%s",
  
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text")); 
  
  
$row mysql_fetch_assoc($LoginRS);//ESTO LO PUSE A VER SI FUNCIONABA
  
$LoginRS mysql_query($LoginRS__query$conex) or die(mysql_error());
  
$loginFoundUser mysql_num_rows($LoginRS);
  if (
$loginFoundUser) {
    
    
$loginStrGroup  mysql_result($LoginRS,0,'Estatus');
    
    
//declare two session variables and assign them
    
$_SESSION['MM_Username'] = $loginUsername;
    
$_SESSION['MM_UserGroup'] = $loginStrGroup;     
    
$_SESSION['MM_Nombres'] = $row['Nombres'];
    
$_SESSION['MM_NumIngreso'] = $row['NumIngreso'];//ESTO LO NECESITO IMPLEMENTAR
    
$_SESSION['MM_UltimoIngreso'] = $row['UltimoIngreso'];//ESTO LO NECESITO IMPLEMENTAR
    
$_SESSION['MM_IngresoHora'] = $row['IngresoHora'];//ESTO LO NECESITO IMPLEMENTAR

    
if (isset($_SESSION['PrevUrl']) && false) {
      
$MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
    }
    
header("Location: " $MM_redirectLoginSuccess );
  }
  else {
    
header("Location: "$MM_redirectLoginFailed );
  }
}
?>
  #6 (permalink)  
Antiguo 30/07/2012, 09:53
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Error al crear variable de sesion

lo estas haciendo mal , LO HAS PUESTO FUERA DE PHP.


Código PHP:
Ver original
  1. <?php
  2.  
  3. require_once('../Connections/conex.php');
  4.  
  5. if (!function_exists("GetSQLValueString")) {
  6. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  7. {
  8.   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  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. $loginFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_GET['accesscheck'])) {
  36.   $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  37. }
  38.  
  39. if (isset($_POST['Usuario'])) {
  40.   $loginUsername=$_POST['Usuario'];
  41.   $password=$_POST['Password'];
  42.   $MM_fldUserAuthorization = "Estatus";
  43.   $MM_redirectLoginSuccess = "PanelControl/Administradores/Validar.php";
  44.   $MM_redirectLoginFailed = "Error.php";
  45.   $MM_redirecttoReferrer = false;
  46.   mysql_select_db($database_conex, $conex);
  47.      
  48.   $LoginRS__query=sprintf("SELECT Usuario, Password, Estatus FROM usuarios WHERE Usuario=%s AND Password=%s",
  49.   GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  50.  
  51.   $row = mysql_fetch_assoc($LoginRS);//ESTO LO PUSE A VER SI FUNCIONABA
  52.   $LoginRS = mysql_query($LoginRS__query, $conex) or die(mysql_error());
  53.   $loginFoundUser = mysql_num_rows($LoginRS);
  54.   if ($loginFoundUser) {
  55.    
  56.     $loginStrGroup  = mysql_result($LoginRS,0,'Estatus');
  57.    
  58.     //declare two session variables and assign them
  59.     $_SESSION['MM_Username'] = $loginUsername;
  60.     $_SESSION['MM_UserGroup'] = $loginStrGroup;    
  61.     $_SESSION['MM_Nombres'] = $row['Nombres'];
  62.     $_SESSION['MM_NumIngreso'] = $row['NumIngreso'];//ESTO LO NECESITO IMPLEMENTAR
  63.     $_SESSION['MM_UltimoIngreso'] = $row['UltimoIngreso'];//ESTO LO NECESITO IMPLEMENTAR
  64.     $_SESSION['MM_IngresoHora'] = $row['IngresoHora'];//ESTO LO NECESITO IMPLEMENTAR
  65.  
  66.     if (isset($_SESSION['PrevUrl']) && false) {
  67.       $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];    
  68.     }
  69.     header("Location: " . $MM_redirectLoginSuccess );
  70.   }
  71.   else {
  72.     header("Location: ". $MM_redirectLoginFailed );
  73.   }
  74. }
  75. ?>

Última edición por webankenovi; 30/07/2012 a las 10:06
  #7 (permalink)  
Antiguo 30/07/2012, 10:48
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Error al crear variable de sesion

He realizado lo que me dices y cuando actuzalizo el formulario en primera insatncia me sale este error:


Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at G:\AppServ\www\web\modulos\Admin.php:1) in G:\AppServ\www\web\modulos\Admin.php on line 2



y al darle logueo me devuelve a la pagina de logue o y me muestra este error:


Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at G:\AppServ\www\petrominerales\modulos\Admin.php:1) in G:\AppServ\www\web\modulos\Admin.php on line 2

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in G:\AppServ\www\web\modulos\Admin.php on line 52

Warning: Cannot modify header information - headers already sent by (output started at G:\AppServ\www\web\modulos\Admin.php:1) in G:\AppServ\www\web\modulos\Admin.php on line 70


de verdad que me vuelvo loco no se que hacer no se donde esta el error.
  #8 (permalink)  
Antiguo 30/07/2012, 10:52
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Error al crear variable de sesion

ok sube las 3 paginas tal y como las tienes
logueo
pagina despues logueo
y conex.php
  #9 (permalink)  
Antiguo 30/07/2012, 11:30
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Error al crear variable de sesion

Esta es la pagina de logueo:



Código PHP:
    <?php
    session_start
();
     
    require_once(
'../Connections/conex.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;
    }
    }
     
    
$loginFormAction $_SERVER['PHP_SELF'];
    if (isset(
$_GET['accesscheck'])) {
      
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
    }
     
    if (isset(
$_POST['Usuario'])) {
      
$loginUsername=$_POST['Usuario'];
      
$password=$_POST['Password'];
      
$MM_fldUserAuthorization "Estatus";
      
$MM_redirectLoginSuccess "PanelControl/Administradores/Validar.php";
      
$MM_redirectLoginFailed "Error.php";
      
$MM_redirecttoReferrer false;
      
mysql_select_db($database_conex$conex);
         
      
$LoginRS__query=sprintf("SELECT Usuario, Password, Estatus FROM usuarios WHERE Usuario=%s AND Password=%s",
      
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text"));
     
      
$row mysql_fetch_assoc($LoginRS);//ESTO LO PUSE A VER SI FUNCIONABA
      
$LoginRS mysql_query($LoginRS__query$conex) or die(mysql_error());
      
$loginFoundUser mysql_num_rows($LoginRS);
      if (
$loginFoundUser) {
       
        
$loginStrGroup  mysql_result($LoginRS,0,'Estatus');
       
        
//declare two session variables and assign them
        
$_SESSION['MM_Username'] = $loginUsername;
        
$_SESSION['MM_UserGroup'] = $loginStrGroup;    
        
$_SESSION['MM_Nombres'] = $row['Nombres'];
        
$_SESSION['MM_NumIngreso'] = $row['NumIngreso'];//ESTO LO NECESITO IMPLEMENTAR
        
$_SESSION['MM_UltimoIngreso'] = $row['UltimoIngreso'];//ESTO LO NECESITO IMPLEMENTAR
        
$_SESSION['MM_IngresoHora'] = $row['IngresoHora'];//ESTO LO NECESITO IMPLEMENTAR
     
        
if (isset($_SESSION['PrevUrl']) && false) {
          
$MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
        }
        
header("Location: " $MM_redirectLoginSuccess );
      }
      else {
        
header("Location: "$MM_redirectLoginFailed );
      }
    }
    
?>
<!DOCTYPE html >

<html>

<head>
    <title></title>
    <meta  charset="iso-8859-1" />
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
        <link href="css/ie6.css" rel="stylesheet" type="text/css" />
    <![endif]-->
    <!--[if IE 7]>
        <link href="css/ie7.css" rel="stylesheet" type="text/css" />  
    <![endif]-->
    <link href="../css/style.css" rel="stylesheet" type="text/css">
</head>

<body>

      <div id="background">
              <div id="page">
              
                     <div class="header">
                        <div class="footer">
                            <div class="body">
                                    <div id="sidebar">
                                        <a href="index.html"><img id="logo" src="../images/logo.gif" with="154" height="74" alt="" title=""/></a>
                                        
                                        
                              <ul class="navigation">
                                                <li><a  href="../index.php">INICIO</a></li>
                                <li ><a href="Guia/index.php" >CONSULTA</a></li>
                                <li class="active"><a href="Admin.php">ADMINISTRADOR</a></li>
                                              <li class="last"><a href="Usuarios.php">USUARIOS</a></li>
                                      </ul>
                                        
                                        <div class="connect">
                                             <a href="#" class="facebook">&nbsp;</a>
                                            <a href="#" class="twitter">&nbsp;</a>
                                            <a href="#" class="vimeo">&nbsp;</a>                                        </div>
                                        
                        <div class="footenote">
                                          <span>&copy; Copyright &copy; 2012.</span>
                                          <span>Petrominerales all rights reserved</span>                                        </div>
                                        
                              </div>
              <div id="content">
                                                <div class="content">
                                               <ul class="article">
                                                    <li><a href="#"><img src="../images/Icons/Panel/usario.png" width="48" height="48" alt="" title=""></a>
                                                      <h2><a href="about.html">IDENTIFICACI&Oacute;N EN EL SISTEMA DE ADMINISTRADOR.</a></h2>
                                                        <p>    
                                                           Por    favor    digite    su    nombre    de    usuario    y    contrase&ntilde;a    para    ser    validado    por    el    sistema.</p>
                                                 </li>
                                                    
                                                 <li>Digite: Usuario: admin - Contrase&ntilde;a: 123</li>
                                                 <ul>
                                                   <li>
                                                     <form name="form1" method="POST" action="<?php echo $loginFormAction?>">
                                                       <ul>
                                                         <li>Usuario:
                                                           <input type="text" name="Usuario" id="Usuario">
                                                           Contrase&ntilde;a:
                                                           <input type="password" name="Password" id="Password">
                                                           <input type="submit" name="button" id="button" value="Identificarse">
                                                         </li>
                                                       </ul>
                                                     </form>
                                                   </li>
                                                 </ul>
                                               </ul>
                </div>
                              </div>
                            </div>
                        </div>
                     </div>
                     <div class="shadow">
                     </div>
              </div>    
      </div>    
    
</body>
</html>
  #10 (permalink)  
Antiguo 30/07/2012, 11:31
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Error al crear variable de sesion

Esta es la pagina a donde voy a ir despues de loguearme

Código PHP:
<?php
if (!isset($_SESSION)) {
  
session_start();
}

?>
session_start();
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Insertar datos en MySQL</title>
<style type="text/css">
    <!--
    body {
        font-family: "Trebuchet MS", Tahoma, Arial;
        font-size: 12px;
        color: #333333;
    }
    h2 {
        font-size: 16px;
        color: #CC0000;
    }
    input, select {
        font-family: "Trebuchet MS", Tahoma, Arial;
        font-size: 11px;
        color: #666666;
    }
    -->
    </style>
</head>
<body>
<p><strong>Bienvenido:</strong>  <?php echo $_SESSION['MM_Username']; ?></p>
<p><strong>Permiso:</strong> <?php echo $_SESSION['MM_UserGroup']; ?></p>
<p><strong>Nombres:<?php echo $_SESSION['MM_Nombres']; ?></strong></p>
<p><strong>Numero ingresos:</strong><?php echo $_SESSION['MM_NumIngreso']; ?></p>
<p><strong>Dia de ultimo ingreso:</strong><?php echo $_SESSION['MM_UltimoIngreso']; ?></p>
<p><strong>Hora de Ultimo ingreso:</strong><?php echo $_SESSION['MM_IngresoHora']; ?></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
  #11 (permalink)  
Antiguo 30/07/2012, 11:32
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Error al crear variable de sesion

y esta la apgina de conexion:

Código PHP:
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_conex "localhost";
$database_conex "express";
$username_conex "root";
$password_conex "123456";
$conex mysql_pconnect($hostname_conex$username_conex$password_conex) or trigger_error(mysql_error(),E_USER_ERROR); 
?>
  #12 (permalink)  
Antiguo 30/07/2012, 11:42
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Error al crear variable de sesion

en la pagina de logueo veo todo bien pero parece ser que estas enviando html antes de session_start() asique retira todos los espacios que pueda ver antes y dejarlo todo bien

<?php
session_start();


en la pagina donde vas despues de logearte prueba como yo te dijie
  #13 (permalink)  
Antiguo 30/07/2012, 11:57
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Error al crear variable de sesion

El error esta en la apgina de logueo, como no se trabajar con variables de sesiones no se bieb donde esta el error.

Código PHP:
<?php
    session_start
();
     
    require_once(
'../Connections/conex.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;
    }
    }
     
    
$loginFormAction $_SERVER['PHP_SELF'];
    if (isset(
$_GET['accesscheck'])) {
      
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
    }
     
    if (isset(
$_POST['Usuario'])) {
      
$loginUsername=$_POST['Usuario'];
      
$password=$_POST['Password'];
      
$MM_fldUserAuthorization "Estatus";
      
$MM_redirectLoginSuccess "PanelControl/Administradores/Validar.php";
      
$MM_redirectLoginFailed "Error.php";
      
$MM_redirecttoReferrer false;
      
mysql_select_db($database_conex$conex);
         
      
$LoginRS__query=sprintf("SELECT Usuario, Password, Estatus FROM usuarios WHERE Usuario=%s AND Password=%s",
      
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text"));
     
      
$row mysql_fetch_assoc($LoginRS);//ESTO LO PUSE A VER SI FUNCIONABA
      
$LoginRS mysql_query($LoginRS__query$conex) or die(mysql_error());
      
$loginFoundUser mysql_num_rows($LoginRS);
      if (
$loginFoundUser) {
       
        
$loginStrGroup  mysql_result($LoginRS,0,'Estatus');
       
        
//declare two session variables and assign them
        
$_SESSION['MM_Username'] = $loginUsername;
        
$_SESSION['MM_UserGroup'] = $loginStrGroup;    
        
$_SESSION['MM_Nombres'] = $row['Nombres'];
        
$_SESSION['MM_NumIngreso'] = $row['NumIngreso'];//ESTO LO NECESITO IMPLEMENTAR
        
$_SESSION['MM_UltimoIngreso'] = $row['UltimoIngreso'];//ESTO LO NECESITO IMPLEMENTAR
        
$_SESSION['MM_IngresoHora'] = $row['IngresoHora'];//ESTO LO NECESITO IMPLEMENTAR
     
        
if (isset($_SESSION['PrevUrl']) && false) {
          
$MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
        }
        
header("Location: " $MM_redirectLoginSuccess );
      }
      else {
        
header("Location: "$MM_redirectLoginFailed );
      }
    }
    
?>
<!DOCTYPE html >

<html>

<head>
    <title></title>
    <meta  charset="iso-8859-1" />
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
        <link href="css/ie6.css" rel="stylesheet" type="text/css" />
    <![endif]-->
    <!--[if IE 7]>
        <link href="css/ie7.css" rel="stylesheet" type="text/css" />  
    <![endif]-->
    <link href="../css/style.css" rel="stylesheet" type="text/css">
</head>

<body>

      <div id="background">
              <div id="page">
              
                     <div class="header">
                        <div class="footer">
                            <div class="body">
                                    <div id="sidebar">
                                        <a href="index.html"><img id="logo" src="../images/logo.gif" with="154" height="74" alt="" title=""/></a>
                                        
                                        
                              <ul class="navigation">
                                                <li><a  href="../index.php">INICIO</a></li>
                                <li ><a href="Guia/index.php" >CONSULTA</a></li>
                                <li class="active"><a href="Admin.php">ADMINISTRADOR</a></li>
                                              <li class="last"><a href="Usuarios.php">USUARIOS</a></li>
                                      </ul>
                                        
                                        <div class="connect">
                                             <a href="#" class="facebook">&nbsp;</a>
                                            <a href="#" class="twitter">&nbsp;</a>
                                            <a href="#" class="vimeo">&nbsp;</a>                                        </div>
                                        
                        <div class="footenote">
                                          <span>&copy; Copyright &copy; 2012.</span>
                                          <span>Petrominerales all rights reserved</span>                                        </div>
                                        
                              </div>
              <div id="content">
                                                <div class="content">
                                               <ul class="article">
                                                    <li><a href="#"><img src="../images/Icons/Panel/usario.png" width="48" height="48" alt="" title=""></a>
                                                      <h2><a href="about.html">IDENTIFICACI&Oacute;N EN EL SISTEMA DE ADMINISTRADOR.</a></h2>
                                                        <p>    
                                                           Por    favor    digite    su    nombre    de    usuario    y    contrase&ntilde;a    para    ser    validado    por    el    sistema.</p>
                                                 </li>
                                                    
                                                 <li>Digite: Usuario: admin - Contrase&ntilde;a: 123</li>
                                                 <ul>
                                                   <li>
                                                     <form name="form1" method="POST" action="<?php echo $loginFormAction?>">
                                                       <ul>
                                                         <li>Usuario:
                                                           <input type="text" name="Usuario" id="Usuario">
                                                           Contrase&ntilde;a:
                                                           <input type="password" name="Password" id="Password">
                                                           <input type="submit" name="button" id="button" value="Identificarse">
                                                         </li>
                                                       </ul>
                                                     </form>
                                                   </li>
                                                 </ul>
                                               </ul>
                </div>
                              </div>
                            </div>
                        </div>
                     </div>
                     <div class="shadow">
                     </div>
              </div>    
      </div>    
    
</body>
</html>
  #14 (permalink)  
Antiguo 30/07/2012, 12:03
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Error al crear variable de sesion

segun los warnings que posteaste anteriormente el problema esta en session_start() ok

sale porque ya has enviado alguna contenido en html antes de enviar a session_start.

asegurate de retirar html antes cualquier espacio caracter etc

eso es tu unico problema
  #15 (permalink)  
Antiguo 30/07/2012, 12:46
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Error al crear variable de sesion

Retiro el html en cual? en la pagina de login o en el que recibo?.
  #16 (permalink)  
Antiguo 30/07/2012, 12:53
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Error al crear variable de sesion

haber amigo el problema es que entre estas 2 etiquetas

1 <?php
2 session_start()

no puede haber html ok retira espacios que suele ser el problemas mas comun , es decir antes de session_start() no puedes generar html

evidentemente como generas codigo con dreamweaver no entiendes bien tu codigo y luego pasa que cualquier error que aparezca te ves envuelto en un caos mi sugerencia crear todo el codigo tu manualmente asi aprenderas y conoceras tu codigo como si fuera tu hijo
  #17 (permalink)  
Antiguo 30/07/2012, 13:52
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Error al crear variable de sesion

Ya realize de cero no me vota errores pero en la pagina de recibo no me muestra las variables de sesion: MM_NumIngreso, MM_UltimoIngreso, MM_IngresoHora. ALguien ayudeme a ver que me hace falta, gracias

este es el codigo donde logueo:


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;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  
session_start();
}

$loginFormAction $_SERVER['PHP_SELF'];
if (isset(
$_GET['accesscheck'])) {
  
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset(
$_POST['Usuario'])) {
  
$loginUsername=$_POST['Usuario'];
  
$password=$_POST['Password'];
  
$MM_fldUserAuthorization "Estatus";
  
$MM_redirectLoginSuccess "PanelControl/Administradores/Validar.php";
  
$MM_redirectLoginFailed "Admin.php";
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_conex$conex);
      
  
$LoginRS__query=sprintf("SELECT Usuario, Password, Estatus 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,'Estatus');
    
    
//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 );
  }
}
?>
<!DOCTYPE html >

<html>

<head>
    <title></title>
    <meta  charset="iso-8859-1" />
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
        <link href="css/ie6.css" rel="stylesheet" type="text/css" />
    <![endif]-->
    <!--[if IE 7]>
        <link href="css/ie7.css" rel="stylesheet" type="text/css" />  
    <![endif]-->
    <link href="../css/style.css" rel="stylesheet" type="text/css">
    <style type="text/css">
<!--
.Estilo1 {
    color: #FFFFFF;
    font-weight: bold;
}
-->
    </style>
</head>

<body>

      <div id="background">
              <div id="page">
              
                     <div class="header">
                        <div class="footer">
                            <div class="body">
                                    <div id="sidebar">
                                        <a href="index.html"><img id="logo" src="http://www.forosdelweb.com/f18/images/logo.gif" with="154" height="74" alt="" title=""/></a>
                                        
                                        
                              <ul class="navigation">
                                                <li><a  href="http://www.forosdelweb.com/f18/index.php">INICIO</a></li>
                                <li ><a href="Guia/index.php" >CONSULTA</a></li>
                                <li class="active"><a href="Admin.php">ADMINISTRADOR</a></li>
                                              <li class="last"><a href="Usuarios.php">USUARIOS</a></li>
                                      </ul>
                                        
                                        <div class="connect">
                                             <a href="#" class="facebook">&nbsp;</a>
                                            <a href="#" class="twitter">&nbsp;</a>
                                            <a href="#" class="vimeo">&nbsp;</a>                                        </div>
                                        
                        <div class="footenote">
                                          <span>&copy; Copyright &copy; 2012.</span>
                                          <span>Petrominerales all rights reserved</span>                                        </div>
                                        
                              </div>
              <div id="content">
                                                <div class="content">
                                               <ul class="article">
                                                    <li><a href="#"><img src="http://www.forosdelweb.com/f18/images/Icons/Panel/usario.png" width="48" height="48" alt="" title=""></a>
                                                      <h2><a href="about.html">IDENTIFICACI&Oacute;N EN EL SISTEMA DE ADMINISTRADOR.</a></h2>
                                                        <p>    
                                                           Por    favor    digite    su    nombre    de    usuario    y    contrase&ntilde;a    para    ser    validado    por    el    sistema.</p>
                                                 </li>
                                                    
                                                 <li>Digite: Usuario: admin - Contrase&ntilde;a: 123</li>
                                                 <ul>
                                                   <li>
                                                     <form action="<?php echo $loginFormAction?>" method="POST" name="form1" class="Estilo1">
Usuario:
  <label>
  <input type="text" name="Usuario" id="Usuario">
  </label>
<p>Contrase&ntilde;a:
<label>
                                                         <input type="text" name="Password" id="Password">
                                                         </label>
                                                       </p>
                                                       <p>
                                                         <label>
                                                         <input type="submit" name="Logearse" id="Logearse" value="Enviar">
                                                         </label>
                                                       </p>
                                                     </form>
                                                   </li>
                                                 </ul>
                                               </ul>
                </div>
                              </div>
                            </div>
                        </div>
                     </div>
                     <div class="shadow">
                     </div>
              </div>    
      </div>    
    
</body>
</html>
y este donde recibo:

Código PHP:
<?php

  session_start
();


?>

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Insertar datos en MySQL</title>
<style type="text/css">
    <!--
    body {
        font-family: "Trebuchet MS", Tahoma, Arial;
        font-size: 12px;
        color: #333333;
    }
    h2 {
        font-size: 16px;
        color: #CC0000;
    }
    input, select {
        font-family: "Trebuchet MS", Tahoma, Arial;
        font-size: 11px;
        color: #666666;
    }
    -->
    </style>
</head>
<body>
<p><strong>Bienvenido:</strong>  <?php echo $_SESSION['MM_Username']; ?></p>
<p><strong>Permiso:</strong> <?php echo $_SESSION['MM_UserGroup']; ?></p>
<p><strong>Nombres:<?php echo $_SESSION['MM_Nombres']; ?></strong></p>
<p><strong>Numero ingresos:</strong><?php echo $_SESSION['MM_NumIngreso']; ?></p>
<p><strong>Dia de ultimo ingreso:</strong><?php echo $_SESSION['MM_UltimoIngreso']; ?></p>
<p><strong>Hora de Ultimo ingreso:</strong><?php echo $_SESSION['MM_IngresoHora']; ?></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>

Etiquetas: 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 03:44.