Foros del Web » Programando para Internet » PHP »

Warning: session_start() [function.session-start]: Cannot send session cookie - heade

Estas en el tema de Warning: session_start() [function.session-start]: Cannot send session cookie - heade en el foro de PHP en Foros del Web. Estimados, gusto en saludar. mi error es el sigiente al momento de crear sesiones Código: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already ...
  #1 (permalink)  
Antiguo 24/07/2007, 15:17
Avatar de seik!  
Fecha de Ingreso: mayo-2006
Mensajes: 492
Antigüedad: 18 años
Puntos: 6
Exclamación Warning: session_start() [function.session-start]: Cannot send session cookie - heade

Estimados, gusto en saludar.

mi error es el sigiente al momento de crear sesiones

Código:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by
he leido todos sus comentarios respecto a este tema pero tengo el mismo error y nada.. no he logrado solucionarlo... segun mi phpinfo() la configuracion que poseo es la siguiente.

session.auto_start Off
session.bug_compat_42 On
session.bug_compat_warn On
session.cache_expire 180
session.cache_limiter nocache
session.cookie_domain C:\AppServ\www\site\Cookie
session.cookie_lifetime 0
session.cookie_path C:\AppServ\www\site\Cookie
session.cookie_secure Off
session.entropy_file no value
session.entropy_length 0
session.gc_divisor 100
session.gc_maxlifetime 1440
session.gc_probability 1
session.hash_bits_per_character 4
session.hash_function 0
session.name PHPSESSID
session.referer_check no value
session.save_handler files
session.save_path C:\AppServ\www\site\Cookie
session.serialize_handler php
session.use_cookies On
session.use_only_cookies Off
session.use_trans_sid 0

tambien he verificado que no existan espacios en blanco antes del los header y todo pero mi error no desaparece..

espero puedan colaborar con esto que me tiene de cabeza :(

Saludos
__________________
sEIK! -Chile-
Analista Programador.
  #2 (permalink)  
Antiguo 24/07/2007, 15:19
Avatar de jerkan  
Fecha de Ingreso: septiembre-2005
Mensajes: 1.607
Antigüedad: 18 años, 7 meses
Puntos: 19
Re: Warning: session_start() [function.session-start]: Cannot send session cookie - h

Podrías mostrar el mensaje de error completo y los scripts a los que hace referencia?
  #3 (permalink)  
Antiguo 24/07/2007, 15:21
Avatar de seik!  
Fecha de Ingreso: mayo-2006
Mensajes: 492
Antigüedad: 18 años
Puntos: 6
De acuerdo Re: Warning: session_start() [function.session-start]: Cannot send session cookie - h

Gracias por responder..
Este es el error
Código:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\AppServ\www\site\php\validar_usuario.php:6) in C:\AppServ\www\site\php\validar_usuario.php on line 18

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\site\php\validar_usuario.php:6) in C:\AppServ\www\site\php\validar_usuario.php on line 18

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\site\php\validar_usuario.php:6) in C:\AppServ\www\site\php\validar_usuario.php on line 25
y este es el codigo de la pagina que lo genera
Código PHP:
<?php require("../config.inc.php");?>
<html>
<title>Verificando Usuario...</title>
</head>
<body>
<?php
$usuario 
$_POST["txt_usuario"];
$clave $_POST["txt_clave"];
// Busca en BD el usuario ingresado
        
$sql "SELECT * ";
        
$sql.= "FROM gschool.usuario WHERE usu_rut='".$usuario."'";
        
$rs_datos select_data($sql, &$f_est, &$c_est);
        
$ls_datos mysql_fetch_array($rs_datos);
        if (
$f_est 0){
            if (
strtolower($ls_datos["usu_clave"]) == strtolower($clave)){
                
$login $ls_datos["usu_rut"];
                
$perfil $ls_datos["usu_perfil"];
                
session_start();
                
session_register("autentificado");
                
session_register("usu_login");
                
session_register("usu_perfil");
                
$autentificado "1";
                
$usu_login $login;
                
$usu_perfil $perfil;
                
header("Location : ".$gserver."php/home.php");
            }else{
                
header("Location:".$gserver."index.php?err=2");
                exit;
                    }
        }else{
        
header("Location:".$gserver."index.php?err=1");
            exit;
            }
        
mysql_free_result($rs_datos);?>
</body>
</html>
espero sirva
__________________
sEIK! -Chile-
Analista Programador.
  #4 (permalink)  
Antiguo 24/07/2007, 15:41
Avatar de urgido  
Fecha de Ingreso: febrero-2005
Mensajes: 2.351
Antigüedad: 19 años, 2 meses
Puntos: 25
Re: Warning: session_start() [function.session-start]: Cannot send session cookie - h

en el archivo home.php tienes session_start(); ?
__________________
Hospedaje Web al mejor costo!
  #5 (permalink)  
Antiguo 24/07/2007, 15:43
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Re: Warning: session_start() [function.session-start]: Cannot send session cookie - h

Ese error es tipico y te sale porque ya haz enviado alguna contenido en html antes de enviar a session_start.

Saludos.
  #6 (permalink)  
Antiguo 24/07/2007, 15:44
Avatar de jerkan  
Fecha de Ingreso: septiembre-2005
Mensajes: 1.607
Antigüedad: 18 años, 7 meses
Puntos: 19
Re: Warning: session_start() [function.session-start]: Cannot send session cookie - h

El error está claro. Los tags html que tienes entre las líneas 2 y 5 son los que provocan el warning.
Deberías hacer una página de procesado (con los header al final para redirigir y otra para mostrar los resultados (con el código html).

Un saludo
  #7 (permalink)  
Antiguo 24/07/2007, 18:13
Avatar de seik!  
Fecha de Ingreso: mayo-2006
Mensajes: 492
Antigüedad: 18 años
Puntos: 6
Re: Warning: session_start() [function.session-start]: Cannot send session cookie - h

Gracias... elimine el HTML y todo funciono ok!

ByeS!
__________________
sEIK! -Chile-
Analista Programador.
  #8 (permalink)  
Antiguo 14/11/2007, 06:15
 
Fecha de Ingreso: noviembre-2007
Mensajes: 30
Antigüedad: 16 años, 5 meses
Puntos: 0
Re: Warning: session_start() [function.session-start]: Cannot send session cookie - h

Hola Amigos: Me surge este problema necesito saber como lo soluciono, puede ser que las register_globals estén en off? sino no se que puede ser. Envío el archivo que me da el error. Gracias

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /var/www/localhost/htdocs/servicio/conexion.php:9) in /var/www/localhost/htdocs/servicio/validar.php on line 14

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/localhost/htdocs/servicio/conexion.php:9) in /var/www/localhost/htdocs/servicio/validar.php on line 14

Warning: Cannot modify header information - headers already sent by (output started at /var/www/localhost/htdocs/servicio/conexion.php:9) in /var/www/localhost/htdocs/servicio/validar.php on line 24

Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0


<?php include("conexion.php");
$nick=$_POST["user"];
$pass=$_POST["pass"];
$pass=md5($pass);
$query="SELECT * FROM usuario WHERE";
$query.=" (user='$nick' and pass='$pass')";
$result = mysql_db_query($dbname,$query);
//si no devuelve coincidencias entonces vuelvo al login.
if (mysql_num_rows($result))
{
while($fila = mysql_fetch_array($result))
{
session_name("loginUsuario");
session_start();
$id=$fila["id"];
$nombre=$fila["nombre"];
$apellido=$fila["apellido"];
$user=$fila["user"];
$pass=$fila["pass"];
$rol=$fila["rol"];
$_SESSION["validado"]="SI";
$_SESSION["ultimoAcceso"]= date("Y-n-j H:i:s");
session_register("id","nombre","apellido","user"," pass","rol");
header("Location: menu.php ");
}
mysql_free_result($result);
}
else
{
header("Location: incorrecto.php");
}
?>
  #9 (permalink)  
Antiguo 14/11/2007, 06:22
Avatar de Wallack  
Fecha de Ingreso: diciembre-2006
Ubicación: España / Santander
Mensajes: 61
Antigüedad: 17 años, 4 meses
Puntos: 2
Re: Warning: session_start() [function.session-start]: Cannot send session cookie - h

Si no quieres quitar el html siempre puedes tirar de buffer:

ob_start(); al principio de tu script.

ob_flush(); al final del script.
  #10 (permalink)  
Antiguo 14/11/2007, 06:57
Avatar de Yranac  
Fecha de Ingreso: junio-2007
Mensajes: 125
Antigüedad: 16 años, 10 meses
Puntos: 1
Re: Warning: session_start() [function.session-start]: Cannot send session cookie - h

Cita:
Iniciado por basko3k Ver Mensaje
Hola Amigos: Me surge este problema necesito saber como lo soluciono, puede ser que las register_globals estén en off? sino no se que puede ser. Envío el archivo que me da el error. Gracias

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /var/www/localhost/htdocs/servicio/conexion.php:9) in /var/www/localhost/htdocs/servicio/validar.php on line 14

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/localhost/htdocs/servicio/conexion.php:9) in /var/www/localhost/htdocs/servicio/validar.php on line 14

Warning: Cannot modify header information - headers already sent by (output started at /var/www/localhost/htdocs/servicio/conexion.php:9) in /var/www/localhost/htdocs/servicio/validar.php on line 24

Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0


<?php include("conexion.php");
$nick=$_POST["user"];
$pass=$_POST["pass"];
$pass=md5($pass);
$query="SELECT * FROM usuario WHERE";
$query.=" (user='$nick' and pass='$pass')";
$result = mysql_db_query($dbname,$query);
//si no devuelve coincidencias entonces vuelvo al login.
if (mysql_num_rows($result))
{
while($fila = mysql_fetch_array($result))
{
session_name("loginUsuario");
session_start();
$id=$fila["id"];
$nombre=$fila["nombre"];
$apellido=$fila["apellido"];
$user=$fila["user"];
$pass=$fila["pass"];
$rol=$fila["rol"];
$_SESSION["validado"]="SI";
$_SESSION["ultimoAcceso"]= date("Y-n-j H:i:s");
session_register("id","nombre","apellido","user"," pass","rol");
header("Location: menu.php ");
}
mysql_free_result($result);
}
else
{
header("Location: incorrecto.php");
}
?>
Te dice que no puede iniciar sesión porque ya hay salida al navegador (un echo, un print, un trozo de html (como un espacio en blanco, una línea en blanco)) además dice que esa salida se produce en el fichero:
Código:
/var/www/localhost/htdocs/servicio/validar.php
en la línea 14
__________________
mais só os ignorantes e féridos e duros, imbéciles e escuros non nos entenden, non.
Visita Mi web
  #11 (permalink)  
Antiguo 14/11/2007, 07:19
 
Fecha de Ingreso: noviembre-2007
Mensajes: 30
Antigüedad: 16 años, 5 meses
Puntos: 0
Re: Warning: session_start() [function.session-start]: Cannot send session cookie - h

Ya resolví el problema era una línea en blanco, muchas gracias por eso, pero ahora me surge otro por demás importante.
Me tira este error cuando hago el logout
Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in /var/www/localhost/htdocs/servicio/salir.php on line 13
Y obviamente no me termina la sesión.
Necesito nuevamente de sus mentes brillantes. Gracias
  #12 (permalink)  
Antiguo 14/11/2007, 07:21
 
Fecha de Ingreso: noviembre-2007
Mensajes: 30
Antigüedad: 16 años, 5 meses
Puntos: 0
Re: Warning: session_start() [function.session-start]: Cannot send session cookie - h

Ya resolví el problema era una línea en blanco, muchas gracias por eso, pero ahora me surge otro por demás importante.
Me tira este error cuando hago el logout
Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in /var/www/localhost/htdocs/servicio/salir.php on line 13
Y obviamente no me termina la sesión.
Les envío el código del salir.php:

<?php
$hoy=date("y/m/d");
$hora=date("H:i");?>
<TABLE style="BORDER-COLLAPSE: collapse" height=1 width=100% >
<TBODY>
<TR><TD bgColor="lightsteelblue" height=1>
<div align="right">En Bariloche es: <?$hoy=date("d/m/y H:i");echo"$hoy"; ?></div>
</TD><TR/>
</TBODY>
</TABLE>
<?
session_start();
session_destroy();
?>
<html>
<head>
<title>Has salido!!</title>
</head>
<body bgcolor="">
<br><br><center><img alt="logoOficialCNEA (5K)" src="logoOficialCNEA.gif" height="88" width="88" />
<center><table border=0 cellspacing=1 cellpadding=6>
<tr><td><font size=6 color = "#3333ff" >* ¡Gracias por tu acceso! *</td></tr>
<br>
<br>
<tr><td><center><a href=index.php><font size=4 color=blue>* INGRESAR *</a></tr></td>
</body>
</html>

Necesito nuevamente de sus mentes brillantes. Gracias
  #13 (permalink)  
Antiguo 14/11/2007, 07:27
Avatar de Yranac  
Fecha de Ingreso: junio-2007
Mensajes: 125
Antigüedad: 16 años, 10 meses
Puntos: 1
Re: Warning: session_start() [function.session-start]: Cannot send session cookie - h

Puede ser lo mismo, tienes el session_start() despues de código.... y pon también session_unset() por si acaso. Prueba así
Código PHP:
 <?php
 session_start
(); 
$hoy=date("y/m/d");
          
$hora=date("H:i");?>
         <TABLE  style="BORDER-COLLAPSE: collapse" height=1  width=100% >
         <TBODY>
         <TR><TD bgColor="lightsteelblue" height=1>
         <div align="right">En Bariloche es: <?$hoy=date("d/m/y H:i");echo"$hoy"?></div>
         </TD><TR/>
         </TBODY>
         </TABLE>
         <?
session_unset
();
session_destroy(); 
?> 
<html> 
<head> 
<title>Has salido!!</title> 
</head> 
<body bgcolor=""> 
<br><br><center><img alt="logoOficialCNEA (5K)" src="logoOficialCNEA.gif" height="88" width="88" />
<center><table border=0 cellspacing=1 cellpadding=6>
<tr><td><font size=6 color = "#3333ff" >* ¡Gracias por tu acceso! *</td></tr>
<br> 
<br> 
<tr><td><center><a href=index.php><font size=4 color=blue>* INGRESAR *</a></tr></td>
</body> 
</html>
__________________
mais só os ignorantes e féridos e duros, imbéciles e escuros non nos entenden, non.
Visita Mi web
  #14 (permalink)  
Antiguo 14/11/2007, 07:39
 
Fecha de Ingreso: noviembre-2007
Mensajes: 30
Antigüedad: 16 años, 5 meses
Puntos: 0
Re: Warning: session_start() [function.session-start]: Cannot send session cookie - h

Bárbaro me desapareció el error pero no me destruye la sesión que es lo que necesito. Cuando le doy logout va a salir.php y ahi me tiene que destruir la sesión pero no lo hace. Que puede ser?
  #15 (permalink)  
Antiguo 14/11/2007, 07:45
Avatar de Yranac  
Fecha de Ingreso: junio-2007
Mensajes: 125
Antigüedad: 16 años, 10 meses
Puntos: 1
Re: Warning: session_start() [function.session-start]: Cannot send session cookie - h

Pues prueba resetenado también el array $_SESSION
Código PHP:
 <?php
 session_start
(); 
$hoy=date("y/m/d");
          
$hora=date("H:i");?>
         <TABLE  style="BORDER-COLLAPSE: collapse" height=1  width=100% >
         <TBODY>
         <TR><TD bgColor="lightsteelblue" height=1>
         <div align="right">En Bariloche es: <?$hoy=date("d/m/y H:i");echo"$hoy"?></div>
         </TD><TR/>
         </TBODY>
         </TABLE>
         <?
session_unset
();
session_destroy(); 
 
$_SESSION = array();
?> 
<html> 
<head> 
<title>Has salido!!</title> 
</head> 
<body bgcolor=""> 
<br><br><center><img alt="logoOficialCNEA (5K)" src="logoOficialCNEA.gif" height="88" width="88" />
<center><table border=0 cellspacing=1 cellpadding=6>
<tr><td><font size=6 color = "#3333ff" >* ¡Gracias por tu acceso! *</td></tr>
<br> 
<br> 
<tr><td><center><a href=index.php><font size=4 color=blue>* INGRESAR *</a></tr></td>
</body> 
</html>
__________________
mais só os ignorantes e féridos e duros, imbéciles e escuros non nos entenden, non.
Visita Mi web
  #16 (permalink)  
Antiguo 14/11/2007, 07:53
 
Fecha de Ingreso: noviembre-2007
Mensajes: 30
Antigüedad: 16 años, 5 meses
Puntos: 0
Re: Warning: session_start() [function.session-start]: Cannot send session cookie - h

No amigo no funciona no me destruye la sesión.
  #17 (permalink)  
Antiguo 30/01/2008, 20:39
Avatar de amalvarez  
Fecha de Ingreso: enero-2008
Mensajes: 6
Antigüedad: 16 años, 3 meses
Puntos: 0
Re: Warning: session_start() [function.session-start]: Cannot send session cookie - h

Hola
mi problema es el mismo warning, probé cambiando las etiquetas <html>, y no me funcionó, aunque no estoy muy clara de como hacerlo
este es el codigo:

<!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>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="inicio.css">
</head>
<body>
<form method="post" action="../Presentacion/registrar.php" id="form">
<?php
include_once("../AccesoDatos/Consulta_Admin.php");

$user = $_POST['user'];
$pass = $_POST['pass'];

$gestor = new Consulta_Admin();
//$admin = new admin($user,$pass);



if ($gestor->registrar($user,$pass))
{
session_start ();
$_SESSION ['usuario']=$user;
echo $_SESSION ['usuario'];

}
else
echo"<img src=\"imagenes/error.gif\" width=\"35px\" height=\"35px\"\"/><br><br><br>Usuario o contraseña incorrecto";
//echo "<h5> ERROR, usuario o contraseña incorrectos <h5>";
?>

<div id="caja_ext" >
<div id="img">
<img src="imagenes/candado.jpg"/>
</div>
<div id="caja_int">
<h3>ENTRAR AL SISTEMA</h3>
<table width="248" height="134"id="cajita" >
<tr>
<td>Usuario:</td><td><input type="text" name="user"/></td>
</tr>
<tr>
<td>
Contraseña:</td>
<td> <input type="password" name="pass" maxlength="15" /></td>
<tr><td></td>
<td> <input name="submit" type="submit" value="Aceptar"/></td>
</tr>
</table>
</div>
</div>
</form>
</body>

</html>
por favor si alguien puede ayudarme.....Saludos
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

SíEste tema le ha gustado a 2 personas (incluyéndote)




La zona horaria es GMT -6. Ahora son las 13:49.