PHP - Problema con header

 
Vista:

Problema con header

Publicado por Albert Delgado (11 intervenciones) el 23/03/2005 20:43:05
Hola,
Tengo el siguiente codigo:

<html>
<head><title>Web procesante</title>
</head>
<body>
<?php
if(empty($_POST['name'])){
$error.=urlencode("Te falta por introducir el nombre");
}
if(empty($_POST['Greeting'])){
$error.=urlencode("Te falta por introducir el apellido");
}
if(empty($error)){
?>
<table border="0" cellspacing="1" cellpadding="3" bgcolor="353535" align="center">
<tr>
<td bgcolor="#ffffff" colspan="2" align="center">
<?php echo $_POST['Greeting']?>
</td>
</tr>
<td bgcolor="#ffffff" colspan="2" align="center">
<?php echo $_POST['Name']?>
<?php
}else{
header("location:http://localhost/form2.php?error=".$error);
}


?>
</body>
</html>

Y me da problema con lla funcion header, el aviso k me sale es el siguiente:

Warning: Cannot modify header information - headers already sent by (output started at C:\Archivos de programa\Apache Group\Apache2\test\formprocess2.php:5) in C:\Archivos de programa\Apache Group\Apache2\test\formprocess2.php on line 24

Alguien se le ocurre k puede pasar?
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Pregunta repetida (incluye respuesta)

Publicado por Mike79 (669 intervenciones) el 24/03/2005 18:54:42
Por faovr antes de preguntar, revisa las preguntas.
Este tema ya se ha tratado antes.
Y en la documentacion de php esta ampliamente documentado.

http://www.php.net/manual/en/function.header.php

El problema es que la funcion Header no se puede usar a la mitad de un documento.

Tu codigo deberia ser algo asi:

<?php
if(empty($_POST['name'])){
$error.=urlencode("Te falta por introducir el nombre");
}
if(empty($_POST['Greeting'])){
$error.=urlencode("Te falta por introducir el apellido");
}
if(empty($error)){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Web procesante</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<table border="0" cellspacing="1" cellpadding="3" bgcolor="#353535"
align="center">
<tr>
<td bgcolor="#ffffff" colspan="2" align="center">
<?php echo $_POST['Greeting']; ?>
</td>
</tr>
<tr>
<td bgcolor="#ffffff" colspan="2" align="center">
<?php echo $_POST['Name']?>
</td>
</tr>
</table>
</body>
</html>
<?php
}else{
header("location:http://localhost/form2.php?error=".$error);
}
?>

Por cierto, me tome la molestia de corregirlo un poquito, para que se apegue al estandar de html 4.1 (por eso le agrege las lineas y cerre las tablas.

Saludos!
-
Miguel Angel
Mike79
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar