Foros del Web » Programando para Internet » PHP »

error al mostrar la imagen (header...)

Estas en el tema de error al mostrar la imagen (header...) en el foro de PHP en Foros del Web. Bueno estoy intentando hacer un captcha con un formulario pero me da error de: Warning: Cannot modify header information - headers already sent by (output ...
  #1 (permalink)  
Antiguo 30/10/2008, 22:10
Avatar de destor77  
Fecha de Ingreso: noviembre-2004
Ubicación: Gálvez, Santa Fe, Argentina
Mensajes: 2.654
Antigüedad: 19 años, 5 meses
Puntos: 43
error al mostrar la imagen (header...)

Bueno estoy intentando hacer un captcha con un formulario pero me da error de:
Warning: Cannot modify header information - headers already sent by (output started at /home/destor77/public_html/proyectos/includes/head.php:22) in /home/destor77/public_html/proyectos/includes/funciones.php on line 109

el archivo donde genero la imagen es funciones.php:
Código PHP:
function randomText($length) {
    
$pattern "1234567890abcdefghijklmnopqrstuvwxyz";
    for(
$i=0;$i<$length;$i++) {
      
$key .= $pattern{rand(0,35)};
    }
    return 
$key;
}


/**
 * crea un captcha
 *
 * @return image
 */
function captcha(){
      
session_start();
      
$_SESSION['tmptxt'] = randomText(8);
      
$captcha imagecreatefromgif("images/bgcaptcha.gif");
      
$colText imagecolorallocate($captcha000);
      
imagestring($captcha5167$_SESSION['tmptxt'], $colText);
      
header("Content-type: image/gif");
      return 
imagegif($captcha);
      

mi formulario es:
Código PHP:
<div class="paginacion"><? echo $links;?></div>  
        <?
        $imagen
=captcha();
        
?>
        <br>Dejanos tu mensaje:<br><br>
        <form action="" method="post">
          Email: <input name="email" type="text" value="<? echo $_REQUEST['email']; ?>"><br><br>
          Nombre: <input name="nombre" type="text" value="<? echo $_REQUEST['nombre']; ?>"><br><br>
          Mensaje:<br><br>
          <textarea rows="10" cols="30" name="texto"><? echo $_REQUEST['texto']; ?></textarea><br>
          <img src="<? //echo $imagen; ?>" width="100" height="30"><br><br>
          Ingrese codigo de seguridad:<br><br>
          <input name="tmptxt" type="text"><br><br>
          <input name="btget" type="submit" value="Verificar Codigo">
          <input name="action" type="hidden" value="checkdata">
        </form>
        
    <?
      
//session_start();
      
if ($_POST['action'] == "checkdata") {
          if (
$_SESSION['tmptxt'] == $_POST['tmptxt']) {
              
$mensaje=nuevoMensaje($_REQUEST['email'],$_REQUEST['nombre'],$_REQUEST['texto']);
              if(!empty(
$mensaje)){
                if(
$mensaje[0]==1){?>
                                <div id="error">
                                    <? echo $mensaje[1];?>
                                    <a href="index.php?modulo=mensajes">Volver</a>
                                </div>
                             <?
                             

                             else{
                                 if(
$mensaje[0]==0){?>
                                 <div id="ok">
                                    <? echo $mensaje[1];?>
                                    <a href="index.php">Volver</a>
                                </div>
                            
                            <? }   
                }  
            }
        }
    }
?>        
                    
        </div>
y mi head.php tiene:
Código PHP:
<?php
/**
 *  @author : Lucas Martn Sastre
 *     @copyright : Onrico Sistemas
 *     @link : http://www.oniricosistemas.com.ar
 *     @version : 1.1
 *     @package : Leon Gieco
 *  @name : head.php
 * 
 *     contiene todo los includes y la cabecera del html
 */

    
include 'config.php';
    
//include 'funciones.php';
    
include 'PHPPaging.lib.php';
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link type="text/css" rel="stylesheet" href="css/estilos.css" />
<title>LeonGieco.com | SITIO OFICIAL | <? echo $_REQUEST['modulo']; ?></title>
</head>

<body>
<div id="contenedor">
    <div id="logo"><img src="images/hed.jpg" alt="" /></div>
<div id="contenido">

en que le estoy errando para que no se muestre correctamente la imagen?

desde ya muchas gracias
  #2 (permalink)  
Antiguo 30/10/2008, 22:13
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: error al mostrar la imagen (header...)

Las cabeceras tienen que ser enviadas antes que cualquier otra salida al navegador.

Si imprimes algo, te dice que las cabeceras ya fueron enviadas y no pueden ser modificadas.
  #3 (permalink)  
Antiguo 31/10/2008, 00:30
 
Fecha de Ingreso: octubre-2007
Mensajes: 38
Antigüedad: 16 años, 6 meses
Puntos: 0
De acuerdo Respuesta: error al mostrar la imagen (header...)

Cita:
Iniciado por Ronruby Ver Mensaje
Las cabeceras tienen que ser enviadas antes que cualquier otra salida al navegador.

Si imprimes algo, te dice que las cabeceras ya fueron enviadas y no pueden ser modificadas.
Orale y eso como se resuelve?
  #4 (permalink)  
Antiguo 31/10/2008, 00:33
 
Fecha de Ingreso: octubre-2007
Mensajes: 38
Antigüedad: 16 años, 6 meses
Puntos: 0
De acuerdo Respuesta: error al mostrar la imagen (header...)

Y como se resuelve esto amigo. Yo tambien tengo un problema muy similar a este.
  #5 (permalink)  
Antiguo 31/10/2008, 00:43
 
Fecha de Ingreso: mayo-2006
Mensajes: 288
Antigüedad: 17 años, 10 meses
Puntos: 4
Sonrisa Respuesta: error al mostrar la imagen (header...)

Umm ya se crea un documento php llamado img.php con el siguiente codigo:
Código PHP:
header("Content-type: image/gif"); 
include 
"funciones.php";
captcha(); 
Luego tu archivo funciones.php debe quedar asi:

Código PHP:
function randomText($length) { 
    
$pattern "1234567890abcdefghijklmnopqrstuvwxyz"
    for(
$i=0;$i<$length;$i++) { 
      
$key .= $pattern{rand(0,35)}; 
    } 
    return 
$key



/** 
 * crea un captcha 
 * 
 * @return image 
 */ 
function captcha(){ 
      
session_start(); 
      
$_SESSION['tmptxt'] = randomText(8); 
      
$captcha imagecreatefromgif("http://www.forosdelweb.com/images/bgcaptcha.gif"); 
      
$colText imagecolorallocate($captcha000); 
      
imagestring($captcha5167$_SESSION['tmptxt'], $colText); 
      return 
imagegif($captcha); 
       

Y tu archivo de formulario seria:
Código PHP:
<div class="paginacion"><? echo $links;?></div>   
        <? 
        $imagen
="img.php"
        
?> 
        <br>Dejanos tu mensaje:<br><br> 
        <form action="" method="post"> 
          Email: <input name="email" type="text" value="<? echo $_REQUEST['email']; ?>"><br><br> 
          Nombre: <input name="nombre" type="text" value="<? echo $_REQUEST['nombre']; ?>"><br><br> 
          Mensaje:<br><br> 
          <textarea rows="10" cols="30" name="texto"><? echo $_REQUEST['texto']; ?></textarea><br> 
          <img src="<? //echo $imagen; ?>" width="100" height="30"><br><br> 
          Ingrese codigo de seguridad:<br><br> 
          <input name="tmptxt" type="text"><br><br> 
          <input name="btget" type="submit" value="Verificar Codigo"> 
          <input name="action" type="hidden" value="checkdata"> 
        </form> 
         
    <? 
      
//session_start(); 
      
if ($_POST['action'] == "checkdata") { 
          if (
$_SESSION['tmptxt'] == $_POST['tmptxt']) { 
              
$mensaje=nuevoMensaje($_REQUEST['email'],$_REQUEST['nombre'],$_REQUEST['texto']); 
              if(!empty(
$mensaje)){ 
                if(
$mensaje[0]==1){?> 
                                <div id="error"> 
                                    <? echo $mensaje[1];?> 
                                    <a href="index.php?modulo=mensajes">Volver</a> 
                                </div> 
                             <? 
                             
}  
                             else{ 
                                 if(
$mensaje[0]==0){?> 
                                 <div id="ok"> 
                                    <? echo $mensaje[1];?> 
                                    <a href="index.php">Volver</a> 
                                </div> 
                             
                            <? }    
                }   
            } 
        } 
    }
?>         
                     
        </div>
Si tienes problemas con la sessiones escribeme.
Espero te ayude :)
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

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 05:27.