Foros del Web » Programando para Internet » PHP »

header("location:") warning

Estas en el tema de header("location:") warning en el foro de PHP en Foros del Web. Hola a todos, estoy haciendo una pagina, y me topé con esta advertencia: Warning: Cannot modify header information - headers already sent by (output started ...
  #1 (permalink)  
Antiguo 14/07/2011, 16:42
 
Fecha de Ingreso: junio-2010
Mensajes: 117
Antigüedad: 13 años, 10 meses
Puntos: 1
header("location:") warning

Hola a todos, estoy haciendo una pagina, y me topé con esta advertencia:

Warning: Cannot modify header information - headers already sent by (output started at ...header.php:6) in ...ordenar.php on line 26

Estuve leyendo sobre ella y vi que es por espacios, saltos de linea, o el session_start no es lo primero en la pagina, pero mi codigo no tiene espacios y la sesson_start es lo primero en mi codigo, alguien sabe que mas puede ser?.

Lo que hago en la pagina es cargar combos dinamicamente, pero refrescando la pagina con el evento onChange de los combos de js, y hasta hacer click en un boton Enviar se hace un header("location:") que es donde esta el warning, para hacer el header("location:") compruebo que el boton no esté vacio.

Si alguien tiene una respuesta le agradeceria mucho su ayuda.

Saludos
  #2 (permalink)  
Antiguo 14/07/2011, 16:55
Avatar de emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: header("location:") warning

Tu dices no verlos, pero ahi están, sería bueno que nos pases el código que te genera el error

Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.
  #3 (permalink)  
Antiguo 14/07/2011, 17:08
 
Fecha de Ingreso: junio-2010
Mensajes: 117
Antigüedad: 13 años, 10 meses
Puntos: 1
Respuesta: header("location:") warning

Puede ser que no los vea

archivo ordenar.php

<?php session_start();
include_once("../../config.php");
require_once '../../system/ConectorMySQL.class.php';
require_once '../../system/Query.class.php';
include_once("../../estados.php");
$conexion1=new estados();
$estados=$conexion1->seleccionar();
include_once("../../ciudad.php");
$conexion2=new ciudad();
$ciudades=$conexion2->seleccionar();
include_once("../../sucursal.php");
$conexion3=new sucursal();
$sucursales=$conexion3->seleccionar();
include_once("header.php");
if(!empty($_POST['enviar'])){
$_SESSION['carrito']['estado']=$_POST['estado'];
$_SESSION['carrito']['ciudad']=$_POST['ciudad'];
$_SESSION['carrito']['sucursal']=$_POST['sucursal'];
$_SESSION['carrito']['entrega']=$_POST['entrega'];
$_SESSION['carrito']['hora']=$_POST['hora'];
header("location:categorias.php");
}
else{?>
<form id="form1" name="form1" method="post" action="ordenar.php">
<table>
<tr>
<td>Estado:</td>
</tr>
<tr>
<td>
<select name="estado" id="estado" onchange="document.form1.submit()" style="width:200px;">
<option value="0">Seleccione</option>
<? while($filae = mysql_fetch_array($estados)){?>
<option value="<?=$filae['id']?>" <? if($_POST['estado']==$filae['id']){?> selected="selected"<? }?>><?=$filae['nombre']?></option>
<? }?>
</select>
</td>
</tr>
<tr>
<td align="center"><input type="submit" name="enviar" id="enviar" value="Continuar" /></td>
</tr>
</table>
</form>
<?php }
include_once('footer.php');?>

y el archivo header.php contiene la linea 6 es donde empiezan los estilos:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Prueba</title>
<style type="text/css">.link{border:#A63400 solid 1px; background-color:#BF5D30; height:35px; padding-top:8px;}.link a{ color:#ffffff; text-decoration:none; font-size:16px; font-weight:bold; font-family:"Garamond 3"}.link a:hover{ color:#ffffff; text-decoration:underline; font-size:16px; font-weight:bold; font-family:"Garamond 3"}.linkhead{ background-color:#A62800; height:35px; padding-top:8px; font-size:14px; font-weight:bold; font-family:"Garamond 3"; width:100%; text-align:left;}.miga{ color:#FF9E73; text-decoration:none;}.container{color:#ffffff;}span{ color:#ff7b40}.linkbolsa{ border-bottom:#A62800 solid 1px; height:35px; padding-top:8px;}.linkbolsa a{color:#ffffff; text-decoration:none; font-size:16px; font-weight:bold; font-family:"Garamond 3"}.linkbolsa a:hover{color:#ffffff; text-decoration:underline; font-size:16px; font-weight:bold; font-family:"Garamond 3"}.inicio{ color:#ffffff; text-decoration:none;}/*.inicio a{color:#ffffff; text-decoration:none; font-size:16px; font-weight:bold; font-family:"Garamond 3"}.inicio a:hover{color:#ffffff; text-decoration:underline; font-size:16px; font-weight:bold; font-family:"Garamond 3"}*/.select{ width:200px;}#platillo{ width:320px;}#tit_pla{ color:#999999; font-weight:bold;}#tit_pla a{ color:#999999; text-decoration:none;}#tit_pla a:hover{ color:#999999; text-decoration:underline;}#precio{ color:#FFFFFF; font-weight:bold;}</style>
</head>
  #4 (permalink)  
Antiguo 14/07/2011, 17:08
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: header("location:") warning

Claro, los mensajes de error completos indican los archivos y las lineas que producen la salida.

Sería interesante que mostrases los scripts completos que mencionan los errores, así como las lineas previas a lo que indican dichos mensajes.

Edito: el mensaje también menciona un archivo header.php, ¿donde está?
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #5 (permalink)  
Antiguo 14/07/2011, 17:15
 
Fecha de Ingreso: junio-2010
Mensajes: 117
Antigüedad: 13 años, 10 meses
Puntos: 1
Respuesta: header("location:") warning

Cuando hago header("location:categorias.php"); es que tengo el warning, tendrá algo que ver que tenga comentado algunos estilos en el header?
  #6 (permalink)  
Antiguo 14/07/2011, 17:17
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: header("location:") warning

¡Pero por supuesto que si!

¿Que hay en el script header.php?
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #7 (permalink)  
Antiguo 14/07/2011, 17:18
 
Fecha de Ingreso: junio-2010
Mensajes: 117
Antigüedad: 13 años, 10 meses
Puntos: 1
Respuesta: header("location:") warning

Nop, ya los quité y el warning sigue
  #8 (permalink)  
Antiguo 14/07/2011, 17:19
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: header("location:") warning

Cita:
Iniciado por elena_22 Ver Mensaje
Nop, ya los quité y el warning sigue
¿Podrías mostrar ahora el mensaje de error completo que te sale?
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #9 (permalink)  
Antiguo 14/07/2011, 17:21
 
Fecha de Ingreso: junio-2010
Mensajes: 117
Antigüedad: 13 años, 10 meses
Puntos: 1
Respuesta: header("location:") warning

Claro!! Pero es el mismo:

Warning: Cannot modify header information - headers already sent by (output started at ...header.php:6) in ...ordenar.php on line 21
  #10 (permalink)  
Antiguo 14/07/2011, 17:24
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: header("location:") warning

Pues si es el mismo mensaje entonces no solucionaste nada, el mensaje de error claramente dice que la salida se genera en el script header.php, en la linea 6.

¿Serías tan amable de mostrar el código completo de dicho script como te he estado pidiendo desde antes?
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #11 (permalink)  
Antiguo 14/07/2011, 17:27
 
Fecha de Ingreso: junio-2010
Mensajes: 117
Antigüedad: 13 años, 10 meses
Puntos: 1
Respuesta: header("location:") warning

Mis scripts tanto de ordenar.php y header.php estan en el mensaje de arriba, pero te los pongo de nuevo:

archivo ordenar.php

<?php session_start();
include_once("../../config.php");
require_once '../../system/ConectorMySQL.class.php';
require_once '../../system/Query.class.php';
include_once("../../estados.php");
$conexion1=new estados();
$estados=$conexion1->seleccionar();
include_once("../../ciudad.php");
$conexion2=new ciudad();
$ciudades=$conexion2->seleccionar();
include_once("../../sucursal.php");
$conexion3=new sucursal();
$sucursales=$conexion3->seleccionar();
include_once("header.php");
if(!empty($_POST['enviar'])){
$_SESSION['carrito']['estado']=$_POST['estado'];
$_SESSION['carrito']['ciudad']=$_POST['ciudad'];
$_SESSION['carrito']['sucursal']=$_POST['sucursal'];
$_SESSION['carrito']['entrega']=$_POST['entrega'];
$_SESSION['carrito']['hora']=$_POST['hora'];
header("location:categorias.php");
}
else{?>
<form id="form1" name="form1" method="post" action="ordenar.php">
<table>
<tr>
<td>Estado:</td>
</tr>
<tr>
<td>
<select name="estado" id="estado" onchange="document.form1.submit()" style="width:200px;">
<option value="0">Seleccione</option>
<? while($filae = mysql_fetch_array($estados)){?>
<option value="<?=$filae['id']?>" <? if($_POST['estado']==$filae['id']){?> selected="selected"<? }?>><?=$filae['nombre']?></option>
<? }?>
</select>
</td>
</tr>
<tr>
<td align="center"><input type="submit" name="enviar" id="enviar" value="Continuar" /></td>
</tr>
</table>
</form>
<?php }
include_once('footer.php');?>

y el archivo header.php contiene la linea 6 es donde empiezan los estilos:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Prueba</title>
<style type="text/css">.link{border:#A63400 solid 1px; background-color:#BF5D30; height:35px; padding-top:8px;}.link a{ color:#ffffff; text-decoration:none; font-size:16px; font-weight:bold; font-family:"Garamond 3"}.link a:hover{ color:#ffffff; text-decoration:underline; font-size:16px; font-weight:bold; font-family:"Garamond 3"}.linkhead{ background-color:#A62800; height:35px; padding-top:8px; font-size:14px; font-weight:bold; font-family:"Garamond 3"; width:100%; text-align:left;}.miga{ color:#FF9E73; text-decoration:none;}.container{color:#ffffff;}span{ color:#ff7b40}.linkbolsa{ border-bottom:#A62800 solid 1px; height:35px; padding-top:8px;}.linkbolsa a{color:#ffffff; text-decoration:none; font-size:16px; font-weight:bold; font-family:"Garamond 3"}.linkbolsa a:hover{color:#ffffff; text-decoration:underline; font-size:16px; font-weight:bold; font-family:"Garamond 3"}.inicio{ color:#ffffff; text-decoration:none;}/*.inicio a{color:#ffffff; text-decoration:none; font-size:16px; font-weight:bold; font-family:"Garamond 3"}.inicio a:hover{color:#ffffff; text-decoration:underline; font-size:16px; font-weight:bold; font-family:"Garamond 3"}*/.select{ width:200px;}#platillo{ width:320px;}#tit_pla{ color:#999999; font-weight:bold;}#tit_pla a{ color:#999999; text-decoration:none;}#tit_pla a:hover{ color:#999999; text-decoration:underline;}#precio{ color:#FFFFFF; font-weight:bold;}</style>
</head>

Te marque en rojo las lineas 6 y 21 que son donde marca el warning
  #12 (permalink)  
Antiguo 14/07/2011, 17:28
Avatar de emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: header("location:") warning

elena_22
Al momento de hacer tu
header("location:categorias.php");

ya tenes varios includes con html, todos cargados previos a ninguna condición, ahi está el error

Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.
  #13 (permalink)  
Antiguo 14/07/2011, 17:29
 
Fecha de Ingreso: junio-2010
Mensajes: 117
Antigüedad: 13 años, 10 meses
Puntos: 1
Respuesta: header("location:") warning

Los estilos estan sin comentarios, olvide quitarlos antes de ponerte el script
  #14 (permalink)  
Antiguo 14/07/2011, 17:31
 
Fecha de Ingreso: junio-2010
Mensajes: 117
Antigüedad: 13 años, 10 meses
Puntos: 1
Respuesta: header("location:") warning

emprear, ninguno de esos includes tiene contenido html, son solamente consultas a la BD, aún así afecta al header("location:categorias.php");????

Gracias por tu respuesta
  #15 (permalink)  
Antiguo 14/07/2011, 17:31
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: header("location:") warning

Te hago una pregunta retorica, ¿si vas a redireccionar por que cargas el header?

Cita:
Iniciado por elena_22 Ver Mensaje
Los estilos estan sin comentarios, olvide quitarlos antes de ponerte el script
elena_22, cualquier tipo de salida (llamese HTML, estilos, texto, o hasta un simple espacio) genera el error que mencionas.

Aquí te dejo un enlace donde lo explica mas a detalle, de verdad, el error lo tienes frente a ti y no lo puedes ver.

http://www.forosdelweb.com/wiki/PHP:...n_line_4%22%3F

Por favor, procura leer el enlace, ya que si no vas a seguir dándole las mismas vueltas.

Y vamos, en el script header.php tienes un montón de texto, ¿acaso no lo ves?
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #16 (permalink)  
Antiguo 14/07/2011, 17:34
Avatar de emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: header("location:") warning

elena_22:

y esto que contiene?

include_once("header.php");

Yo ahi veo mucho html, nada que tenga nucho que ver con la base de datos

SAludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.
  #17 (permalink)  
Antiguo 14/07/2011, 17:39
 
Fecha de Ingreso: junio-2010
Mensajes: 117
Antigüedad: 13 años, 10 meses
Puntos: 1
Respuesta: header("location:") warning

Gracias a los dos por guiarme, ahora mismo lo arreglo

Saludos

Etiquetas: warning
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 17:05.