Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] Problema con headers

Estas en el tema de Problema con headers en el foro de PHP en Foros del Web. Hola, he estado revisando en 2 servidores y el problema es con los headers de la segunda pagina(index1.php) que pongo. plantilla.php Código PHP: <?php $error ...
  #1 (permalink)  
Antiguo 21/10/2013, 18:19
Avatar de Simon_Echecopar  
Fecha de Ingreso: marzo-2012
Mensajes: 96
Antigüedad: 12 años, 1 mes
Puntos: 0
Problema con headers

Hola,

he estado revisando en 2 servidores y el problema es con los headers de la segunda pagina(index1.php) que pongo.

plantilla.php

Código PHP:
<?php

$error
=false;
if(isset(
$_REQUEST['Submit']))
{
  
$User preg_replace('/[^A-Za-z]/','',$_POST['txtUserName']);
  
$PWD  $_POST['txtPWD'];

  
$dir 'XMLuser/';
  
$arc 'Datos_'.$User.'.xml';
 
  if(
file_exists($dir.$arc))
  {
   
$xml file_get_contents($dir.$arc);
   
$DOM = new DOMDocument('1.0''utf-8');
    
   
$DOM->loadXML($xml);

   if(
$PWD == $DOM->getElementsByTagName('contrasenia')->item(0)->nodeValue)
   {
    
//echo $User;
    
session_start();
    
$_SESSION['username'] = $User;
    
header("location: index1.php");
    die;
   }
   
$error=true;
  }
 }


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="content-type" content="text/html" />
    <meta name="author" content="www.intercambiosvirtuales.org" />
    <link rel="stylesheet" type="text/css" href="css/styles.css" />

    <title> Login </title>

</head>


<script src="Scripts/swfobject_modified.js" type="text/javascript"></script>
<body>
 <header>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
       <h1>
       <video autoplay="true" width="90%" height="100%">
        <source src="vid/animacion.ogv" type='video/ogg' />
        <source src="vid/animacion.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'/>
       </video> 
      </h1>
  <nav> 
         <p id="titulo"> <font face="lobster">OL</font><font face="impact"> SPORTS</font></p>
         <p id="slogan"> DOMINANDO EL BAL&Oacute;N </p>
         <p id="subtitulo"> AGENCIA DE CONTENIDOS DEPORTIVOS</p> 
          <ul id="menu"><font size="2" face="dotum">
            <li style="border-right: 2px solid grey"><a href="index.html">INICIO</a></li>
            <li style="border-right: 2px solid grey"><a href="agencia.html">AGENCIA</a></li>
            <li style="border-right: 2px solid grey"><a href="nosotros.html">NOSOTROS</a></li>
            <li style="border-right: 2px solid grey"><a href="servicios.html">SERVICIOS</a></li>         
            <li style="border-right: 2px solid grey"><a href="contacto.html">CONTACTO</a>
             <ul>
              <li style="border-bottom: 1px solid grey"><a href="clientes.html">CLIENTES</a></li>
              <li style="border-bottom: 1px solid grey"><a href="AgendaDiaXDia.html">AGENDA DE D&Iacute;A A D&Iacute;A</a></li>
              <li style="border-bottom: 1px solid grey"><a href="sportsmedia.html">SPORTS MEDIA</a></li>
              <li style="border-bottom: 1px solid grey"><a href="sportspremium.html">SPORTS PREMIUM</a></li>
             </ul>
            </li>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <li>
             <a href="Clientes.html"><font color="red">Clientes</font></a><br/><a class="sign_up" id="sign_up" href="registroinicio.html">Login/Sign Up</a>
            </li>
           </ul></font>
  </nav>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <section id="espacio"> <br /> </section>
  <section id="espacio"> <br /> </section>
 </header>    
 <section id="espacio"> <br /> </section>
    <section id="contenido">
    
     <section id="espacio"> <br /> </section>
     <section id="espacio"> <br /> </section>
        <section class="principal"><font color="white">
           <form method="POST" method=""> 
            <h1>LOGIN</h1><br/>Usuario:<br/>
            <p><input type="text" id="txtUserName" name="txtUserName"></p>
            <br/>Contrase&ntilde;a:<br/>
            <p><input type="password" id="txtPWD" name="txtPWD"></p>
            <br/>
            <?php
            
if($error){
            echo 
"<p>Invalid User or password</p><br/>";
            
            }
            
?>
            <p><input type="submit" id="Submit" name="Submit" value="Submit"></p></font>
           </form>
        </section>
        <section class="principal">
 
        </section>
        <article class="">

        </article>
    </section>

</body>
</html>

index1.php

Código PHP:
<?php
 
 
@session_start();
 
//echo 'XMLuser/'.$_SESSION['username'].'.xml';
 
if(!file_exists('XMLuser/'.$_SESSION['username'].'.xml'))
 {
        exit(
header("location: login.php"));
 }
 
?>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="content-type" content="text/html" />
    <meta name="author" content="www.intercambiosvirtuales.org" />
    <link rel="stylesheet" type="text/css" href="css/styles.css" />

    <title> Login </title>

</head>

<script src="Scripts/swfobject_modified.js" type="text/javascript"></script>
<body>
 <header>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
       <h1>
       <video autoplay="true" width="90%" height="100%">
        <source src="vid/animacion.ogv" type='video/ogg' />
        <source src="vid/animacion.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'/>
       </video> 
      </h1>
  <nav> 
         <p id="titulo"> <font face="lobster">OL</font><font face="impact"> SPORTS</font></p>
         <p id="slogan"> DOMINANDO EL BAL&Oacute;N </p>
         <p id="subtitulo"> AGENCIA DE CONTENIDOS DEPORTIVOS</p> 
          <ul id="menu"><font size="2" face="dotum">
            <li style="border-right: 2px solid grey"><a href="index.html">INICIO</a></li>
            <li style="border-right: 2px solid grey"><a href="agencia.html">AGENCIA</a></li>
            <li style="border-right: 2px solid grey"><a href="nosotros.html">NOSOTROS</a></li>
            <li style="border-right: 2px solid grey"><a href="servicios.html">SERVICIOS</a></li>         
            <li style="border-right: 2px solid grey"><a href="contacto.html">CONTACTO</a>
             <ul>
              <li style="border-bottom: 1px solid grey"><a href="clientes.html">CLIENTES</a></li>
              <li style="border-bottom: 1px solid grey"><a href="AgendaDiaXDia.html">AGENDA DE D&Iacute;A A D&Iacute;A</a></li>
              <li style="border-bottom: 1px solid grey"><a href="sportsmedia.html">SPORTS MEDIA</a></li>
              <li style="border-bottom: 1px solid grey"><a href="sportspremium.html">SPORTS PREMIUM</a></li>
             </ul>
            </li>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <li>
             <a href="Clientes.html"><font color="red">Clientes</font></a><br/><a class="sign_up" id="sign_up" href="registroinicio.html">Login/Sign Up</a>
            </li>
           </ul></font>
  </nav>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <section id="espacio"> <br /> </section>
  <section id="espacio"> <br /> </section>
 </header>    
 <section id="espacio"> <br /> </section>
    <section id="contenido">
    
     <section id="espacio"> <br /> </section>
     <section id="espacio"> <br /> </section>
        <section class="principal"><font color="white">
         <h1>User Page </h1>
         <h2>Welcome, <?php echo $_SESSION['username'];?></h2>
        </section>
        <section class="principal">
 
        </section>
        <article class="">
         <a href="logout.php">logout</a>
        </article>
    </section>

</body>
</html>
me aparece el titulo
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Agencia_Deportes\public_html\index 1.php:1) in C:\xampp\htdocs\Agencia_Deportes\public_html\index 1.php on line 7

cuando pruebo de forma local y ya en linea ni si quiera el warning sale. No se que hacerle
  #2 (permalink)  
Antiguo 21/10/2013, 19:41
Avatar de neglivv  
Fecha de Ingreso: julio-2011
Mensajes: 103
Antigüedad: 12 años, 9 meses
Puntos: 11
Respuesta: Problema con headers

Yo estuve buscando info de ese error (también tengo el mismo problema) y leí que ocurre porque hay algún espacio en blanco en el archivo (antes del header y el session_start) que php debe estar interpretando como HTML

Trata de quitar todos los espacios en blanco que estén de más en tus archivos y prueba a ver
  #3 (permalink)  
Antiguo 22/10/2013, 09:51
Avatar de Simon_Echecopar  
Fecha de Ingreso: marzo-2012
Mensajes: 96
Antigüedad: 12 años, 1 mes
Puntos: 0
Respuesta: Problema con headers

Muchas gracias, Justo el problema eran los espacios en blanco.

Etiquetas: headers, html, registro
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 08:25.