Foros del Web » Programando para Internet » PHP »

ayuda urgente con header!

Estas en el tema de ayuda urgente con header! en el foro de PHP en Foros del Web. Miren tengo un problema de un libro de visitas. Resulta que cuando envio el formulario para que se guarde el mensaje en el archivo luego ...
  #1 (permalink)  
Antiguo 24/01/2004, 10:13
 
Fecha de Ingreso: diciembre-2002
Ubicación: Santiago de Chile
Mensajes: 350
Antigüedad: 21 años, 4 meses
Puntos: 0
ayuda urgente con header!

Miren tengo un problema de un libro de visitas. Resulta que cuando envio el formulario para que se guarde el mensaje en el archivo luego al redireccionar me da este error:

Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/usuario/httpdocs/libro/yapgb.php:5) in /home/httpd/vhosts/usuario/httpdocs/libro/yapgb.php on line 109

La línea 109 tiene esto:

Código PHP:
header("location: $gbIndex"); 
y Aqui les dejo el archivo completo ( yapgb.php )

http://www.payasadas.net/yapgb.txt


Aqui el config.php

http://www.payasadas.net/config.txt

Aqui el formulario (temp_sign.html )
http://www.payasadas.net/temp_sign.txt
__________________
Animacion de cumpleaños

Última edición por blackseba; 24/01/2004 a las 10:15
  #2 (permalink)  
Antiguo 24/01/2004, 13:42
Ex Colaborador
 
Fecha de Ingreso: junio-2002
Mensajes: 9.091
Antigüedad: 21 años, 10 meses
Puntos: 16
Hola,

Antes del header() no se puede enviar salida al navegador. Ni HTML, ni echo, ni espacios en blanco, ni lineas vacias.

Y tu tienes un monton de HTML antes.

Saludos.
__________________
Josemi

Aprendiz de mucho, maestro de poco.
  #3 (permalink)  
Antiguo 24/01/2004, 14:20
 
Fecha de Ingreso: diciembre-2002
Ubicación: Santiago de Chile
Mensajes: 350
Antigüedad: 21 años, 4 meses
Puntos: 0
Cita:
Mensaje Original por josemi
Hola,

Antes del header() no se puede enviar salida al navegador. Ni HTML, ni echo, ni espacios en blanco, ni lineas vacias.

Y tu tienes un monton de HTML antes.

Saludos.
Ups tienes razón. Entonces como lo podría solucionar? Existira otra funciona para redireccionar o alguna forma de poder poner mi diseño
__________________
Animacion de cumpleaños
  #4 (permalink)  
Antiguo 24/01/2004, 14:32
Ex Colaborador
 
Fecha de Ingreso: junio-2002
Mensajes: 9.091
Antigüedad: 21 años, 10 meses
Puntos: 16
Cambia la estructura. Haz algo como:
Código PHP:
<?php
// primero el codigo PHP necesario para todas las acciones

// Include configuration file
include ("config.php");

//despues el codigo que redirecciona

// Add a new message

if ($_POST["action"] == "add") {

  
// This if sentence is for protection, this way we avoid
  // doing anything if one of these variables is not set.
  
if  (!isset($_POST["name"]) || !isset($_POST["email"]) || !isset($_POST["message"]) )
    die(
"Error: nothing to add.");

  
// Strip slashes and spaces at the beninning and at the end.
  
$_POST["name"] = trimaddSlashes($_POST["name"]) );
  
$_POST["email"] = trimaddSlashes($_POST["email"]) );
  if ( isset(
$_POST["url"]) )
    
$_POST["url"] = trimaddSlashes($_POST["url"]) );
  
$_POST["message"] = trimaddSlashes($_POST["message"]) );

  
// Make sure we strip all HTML tags from name, email and url
  
$_POST["name"] = strip_tags($_POST["name"]);
  
$_POST["email"] = strip_tags($_POST["email"]);
  if ( isset(
$_POST["url"]) )
    
$_POST["url"] = strip_tags($_POST["url"]);

  
// Delete not allowed html tags
  
$_POST["message"] = strip_tags($_POST["message"], $gbAllowedTags);
  
// Make sure the message is stored in one line
  
$_POST["message"] = str_replace("\n""<br>"$_POST["message"]);
  
$_POST["message"] = str_replace("\r"""$_POST["message"]);
  
// Change the | bars for their HTML equivalent
  
$_POST["message"] = str_replace("|""&brvbar;"$_POST["message"]);

  
// The current date
  
$date time();

  
// Open the entries file for adding a new one to the end of the file
  
$fp fopen($gbFile"a") or die("Error reading data file.");

  
// Writting the new entry to the end of the file
  
$new $_POST["name"]."|".$date."|".$_POST["email"]."|"
        
.$_POST["url"]."|".$_POST["message"]."|[end]";
  
fwrite($fp"$new\n");

  
// Freeing the entries file.
  
fclose($fp);

  
// Redireccionar
  
header("location: $gbIndex");

  exit;  
// se te ha olvidado el exit
}

// y ahora el codigo que genera salida al navegador
?>
<html>
<head>
<title>Titulo del sitio</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
 <!--
 a:link { font-weight: bold; color: #FFFF00; text-decoration: none}
 a:visited { font-weight: bold; color: #FFFF00; text-decoration: none}
 a:hover { font-weight: bold; color: #FF3300; text-decoration: none}
 a:active { font-weight: bold; color: #FFFF00; text-decoration: none}
-->
 </style>
</head>

<body bgcolor="#003366" text="#FFFF00" link="#FFFF00" vlink="#FFFF00" alink="#FFFF00" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="750" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
    <td width="620" align="left" valign="top" background="/main/fondo.jpg" bgcolor="#0099CC"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><br>
      </font> <img src="../biografias/titu.gif" width="320" height="39"> 
      <table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<tr> 
          <td align="center"> <p><?php


// Make sure we have page number
if ( empty($_GET["page"]) )
  
$page 1;
else
  
$page $_GET["page"];

// Show sign form
if ($_GET["action"] == "sign") {
  
// The template file
  
$file "themes/$gbTheme/temp_sign.html";

  
// Reading the template file
  
$fp fopen($file"r") or die("Error reading add template file.");
  
$contents fread($fpfilesize($file));
  
fclose($fp);

  
// Writting the guestbook title
  
$contents str_replace("<!--GB_TITLE-->"$gbTitle$contents);
  
$contents str_replace("<!--GB_INDEX-->"$gbIndex$contents);
  
$contents str_replace("<!--GB_SITEINDEX-->"$gbSiteIndex$contents);
  
$contents str_replace("<!--GB_ALLOWEDTAGS-->"htmlspecialchars($gbAllowedTags), $contents);
  
$contents str_replace("<!--GB_INFO-->"$gbInfo$contents);

  
// Finally, we show the signing form
  
echo $contents;
}
// View messages
else {
  
// Reading the entries file into an array ($text)
  
$text file($gbFile);
  
// How many entries we have
  
$lines count($text);
  
// The first entry to show (according to the page)
  
$limitValue $lines $page*$gbLimit;

 
// ... todo lo demas
?>
...
</map>
</body>
</html>
Esa seria la forma de estructurar los scripts:

primero la parte comun
despues el codigo que realiza la redireccion (sin generar salida)
y para finalizar, la salida HTML con el PHP que genera salida.

Saludos.
__________________
Josemi

Aprendiz de mucho, maestro de poco.
  #5 (permalink)  
Antiguo 24/01/2004, 17:42
 
Fecha de Ingreso: diciembre-2002
Ubicación: Santiago de Chile
Mensajes: 350
Antigüedad: 21 años, 4 meses
Puntos: 0
muchas gracias josemi. Funciona de las mil maravillas
__________________
Animacion de cumpleaños
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 02:02.