Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] problema con header

Estas en el tema de problema con header en el foro de PHP en Foros del Web. Me marca un problema así cuando redirecciono, nunca me había pasado esto: Warning: Cannot modify header information - headers already sent by (output started at ...
  #1 (permalink)  
Antiguo 17/05/2013, 15:46
Avatar de CMushroom  
Fecha de Ingreso: diciembre-2011
Ubicación: Morelos
Mensajes: 99
Antigüedad: 12 años, 3 meses
Puntos: 1
problema con header

Me marca un problema así cuando redirecciono, nunca me había pasado esto:

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\PRINCIPAL\php\SitiosWeb\TiendaVirt ual\ListaNoticia.php:61) in C:\xampp\htdocs\PRINCIPAL\php\SitiosWeb\TiendaVirt ual\Comentarios.php on line 52

Si en vez de usar header utilizo tedireccion con javascript no pasa ningun peoblema y lo hace bien.Que sera?¿.

el codigo es este:

Comentarios.php

Código PHP:
Código PHP:
<?php  
include('Fecha.php'); 

include (
'Conexion.php'); 
$Seleccion mysql_query('SELECT * FROM comentarios WHERE NoticiasID = "'.$_GET["NoticiasID"].'" ')or die(mysql_error()); 
include (
'CerrarConexion.php'); 

$TotalComentarios mysql_num_rows($Seleccion); 
$NumeroMensaje 0

?><div class = "Comentarios"><?php 
if($TotalComentarios == 0
    { 
    echo 
'Nadie ha comentado'
    } 
else 
    { 
    while(
$Registro mysql_fetch_array($Seleccion)) 
        { 
        include_once(
'Funciones.php'); 
        
$NumeroMensaje ++; 

        echo 
'<hr /><div align = "left">'.$Registro['fecha'].'</div><div align = "right">Mensaje #'.$NumeroMensaje.'</div>'
        echo 
'<img class = "shadow" src = "'.$Registro['foto'].'" height = "82"/><br>';   
        echo 
$Registro['usuario'].'<br>'
        echo 
'Dijo: '.filtrar($Registro['firma']).'<hr>'
        } 
    } 
     
if(isset(
$_POST['usuario']) && isset($_POST['firma'])) 
    { 
    
$Mensaje htmlentities(trim(ucfirst($_POST['firma']))); 

    include (
'Conexion.php'); 
    
$Seleccion mysql_query('SELECT * FROM comentarios WHERE usuario = "'.$_SESSION['nombreUsuario'].'" && NoticiasID = "'.$_GET["NoticiasID"].'" && firma = "'.$Mensaje.'" '); 
    include (
'CerrarConexion.php'); 
     
    
$Registro mysql_fetch_array($Seleccion); 
         
    if(
$Mensaje == $Registro['firma']) 
        { 
        echo 
'Comentario ya publicado';     
        } 
    else 
        { 
        include (
'Conexion.php'); 
        
$Insercion mysql_query('INSERT INTO comentarios (usuario, foto, firma, fecha, ip, id, NoticiasID) VALUES ("'.$_SESSION['nombreUsuario'].'", "'.$_SESSION['foto'].'", "'.$Mensaje.'", "'.$fechayhora.'", "'.$_SERVER["REMOTE_ADDR"].'", "'.$_SESSION["id"].'", "'.$_GET["NoticiasID"].'")')or die(mysql_error());  
        include (
'CerrarConexion.php'); 
         
        
header("index.php"); 
        }     
    } 
?></div><?php 

if(isset($_SESSION['nombreUsuario'])) 
    {     
    
?> 
    <center> 
        <form name = "FormularioComentarios" action = "" method = "POST" class = "Formulario"> 
            <table> 
                <tr> 
                    <td align = "right"> 
                          <label for = "usuario"></label> 
                        <input type = "text" name = "usuario" value = "<?php echo $_SESSION['nombreUsuario']; ?>" size = "66" READONLY/> 
                      </td> 
                  </tr> 
                <tr>         
                    <td align = "right"><br /> 
                        <label for = "usuario"></label> 
                        <textarea name = "firma" cols = "50" rows = "7"></textarea> 
                     </td> 
                  </tr> 
                <tr>         
                    <td align = "right"><br /> 
                        <input type = "submit" name = "Accion" value = "Enviar" /> 
                        <input type = "reset" name = "Accion" value = "Borrar">  
                      </td> 
                   </tr>  
              </table> 
        </form> 
        <br /> 
    </center>     
    <?php  
    

?>
sustituyendo el header por esta linea ,:

Código PHP:
$url_actual "http://" $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
echo 
"<script>window.location = '".$url_actual."';</script>"
se soluciona pero quiero dejar el código bien y encontrar el por que.
por si acaso agrego este archivo que mensiona el error

ListaNoticia.php

Código PHP:
Código PHP:
<?php  
$ClausulaConsulta 
''

if(isset(
$_GET['id']) && isset($_GET['categoria'])) 
    { 
    
$CategoriaID $_GET['id']; 
    
$Categoria $_GET['categoria']; 
    
$TituloCategoria 'Noticias en la categoria '.$Categoria
    
$ClausulaConsulta 'WHERE CategoriaID = '.$CategoriaID
    } 

if(! isset(
$_GET['id']) && ! isset($_GET['categoria'])) 
    { 
    
$TituloCategoria 'Todas las noticias'
    } 
     
if(isset(
$_GET['NoticiasID'])) 
    { 
    
$ID $_GET['NoticiasID']; 
    
$ClausulaConsulta 'WHERE NoticiasID = '.$ID
    } 

require_once 
'PHPPaging.lib.php'
$Paginacion = new PHPPaging
  
include (
'Conexion.php');      
$Paginacion->agregarConsulta("SELECT * FROM noticias ".$ClausulaConsulta); 
$Paginacion->ejecutar();   
include (
'CerrarConexion.php'); 

if(
$BuscadorActivado == false && empty($_GET['NoticiasID'])) 
    { 
    
?><div class = "Articulo"><?php 
    
echo '<h2><center>'.$TituloCategoria.'</center></h2>';     
     
    while(
$Registro $Paginacion->fetchResultado()) 
        { 
        include_once(
'Funciones.php'); 
         
        echo 
"<a href='index.php?NoticiasID=$Registro[NoticiasID]'><h3>$Registro[Titulo]</h3></a>"
        echo 
'<p><strong>'.$Registro['Subtitulo'].'</strong> '.$Registro['Fecha']."</p>"
        echo 
'<center><a href = "'.$Registro["Foto"].'"><img src='.$Registro["Foto"].' height = "200"></a></center>'
        echo 
'<p>'.recortar($Registro['Texto'],300)."<a href='index.php?NoticiasID=$Registro[NoticiasID]'>... Seguir leyendo</a></p>"
        } 
    echo 
'<p>Paginas '.$Paginacion->fetchNavegacion().'</p>'
    
?></div><?php   
    


if(
$BuscadorActivado == false && isset($_GET['NoticiasID'])) 
    { 
    
?><div class = "Articulo"><?php 
    
include ('Conexion.php'); 
    
$Seleccion mysql_query("SELECT * FROM noticias $ClausulaConsulta"$LinkBaseDatos) or die(mysql_error); 
    include (
'CerrarConexion.php'); 
      
    while(
$Registro mysql_fetch_array($Seleccion)) 
        { 
        echo 
'<h2>'.$Registro['Titulo'].'</h2>'
        echo 
'<p>'.$Registro['Subtitulo'].' '.$Registro['Fecha'].'</p>'
        echo 
'<center><a href = "'.$Registro["Foto"].'"><img src = '.$Registro['Foto'].' height="200"></a></center>'
        echo 
'<p>'.$Registro['Texto'].'</p>';   
        echo 
'<center>'.$Registro['Video'].'</center>'
        } 
         
    include (
'Comentarios.php'); 
    
?></div><?php 
    

?>
  #2 (permalink)  
Antiguo 17/05/2013, 15:49
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: problema con header

¿Tu problema es este?

¿Por qué me sale "Warning: Cannot modify header information - headers already sent by (output started at 1:2) in 3 on line 4"?

Me pregunto porque ya nadie busca antes de crear un tema.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 17/05/2013, 17:13
Avatar de CMushroom  
Fecha de Ingreso: diciembre-2011
Ubicación: Morelos
Mensajes: 99
Antigüedad: 12 años, 3 meses
Puntos: 1
Respuesta: problema con header

Cita:
Iniciado por pateketrueke Ver Mensaje
Disculpa quizas sea medio lentom para entender, ya habia encontrado alguna info parecida pero no lo comprendo donde esta el error que me sugieres que haga, al parecer estoy incurriendo en lo del echo o el html, que me sugeririas?¿
  #4 (permalink)  
Antiguo 17/05/2013, 17:24
Avatar de Nemutagk
Colaborador
 
Fecha de Ingreso: marzo-2004
Ubicación: México
Mensajes: 2.633
Antigüedad: 20 años
Puntos: 406
Respuesta: problema con header

Cita:
Iniciado por CMushroom Ver Mensaje
Disculpa quizas sea medio lentom para entender, ya habia encontrado alguna info parecida pero no lo comprendo donde esta el error que me sugieres que haga, al parecer estoy incurriendo en lo del echo o el html, que me sugeririas?¿
o.O enserio? esta bastante claro, header() no puede ser utilizado cuando se envia información al navegador ya sea usando echo/print/print_r o cualquier otra función que imprima algo en el navegador, tampoco se debe tener código HMTL o cualquier cosa que se vea en el navegador antes de header()
__________________
Listo?, tendría que tener 60 puntos menos de IQ para considerarme listo!!!
-- Sheldon Cooper
http://twitter.com/nemutagk
PD: No contestaré temas vía mensaje personal =)

Etiquetas: formulario, header, html, mysql, registro, select, sql
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 21:38.