Foros del Web » Programando para Internet » PHP »

Problemas con header al hecer include!!

Estas en el tema de Problemas con header al hecer include!! en el foro de PHP en Foros del Web. Hola amigos, soy relativamente nuevo trabando con php, resulta que estoy tratando de crear un sito con uno pagina maestra, plantilla generica no se como ...
  #1 (permalink)  
Antiguo 20/12/2007, 11:42
 
Fecha de Ingreso: diciembre-2007
Mensajes: 1
Antigüedad: 16 años, 3 meses
Puntos: 0
Problemas con header al hecer include!!

Hola amigos, soy relativamente nuevo trabando con php, resulta que estoy tratando de crear un sito con uno pagina maestra, plantilla generica no se como lo llaman ustedes, lo que quiero con esta plantilla es manejar las diferentes paginas de mi sitio haciendo include en ésta deacurdo a lo que necesite, pero en este sitio tambien manejo formularios que envian datos a la db, los cuales deben redirecionar a otra pagina al usuario una vez se envia los datos para corfimar el envio de los datos. Es aqui donde aparecemi problema, muy comentado en todos los foros ... Warning: Cannot modify header information - headers already sent by.... debido a las razones que ya sabemos, no se puede enviar html, echo antes, etc. mi pregunta es puedes alguien ayudarme a solucionar este problema, alguna funcion, o conoce alguna otra forma de hacer este tipos de cosas??? coloco a continuacion algo parecido al codigo que tengo para mayor idea de lo que deseo hacer.

esta es plantilla generica
<?php $ok = (isset($_GET["op"])) ? $_GET["op"] : exit();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>

<?php formularios($ok)?>
<?php
function formularios($ok){
switch($ok){
case 1: include('../includes/categ.php');
break;
case 2: include('../includes/subfotocat.php');
break;
}
}

?>
</body>
</html>

este es el from categ.php
<?php require_once('../Connections/ep360.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO categoria (codigoCategoria, nombreCategoria) VALUES (%s, %s)",
GetSQLValueString($_POST['codigo'], "text"),
GetSQLValueString($_POST['nombre'], "text"));

mysql_select_db($database_ep360, $ep360);
$Result1 = mysql_query($insertSQL, $ep360) or die(mysql_error());

$insertGoTo = "../html/mensajes.php?op=1";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_ep360, $ep360);
$query_categoria = "SELECT codigoCategoria, nombreCategoria FROM categoria";
$categoria = mysql_query($query_categoria, $ep360) or die(mysql_error());
$row_categoria = mysql_fetch_assoc($categoria);
$totalRows_categoria = mysql_num_rows($categoria);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<table width="400" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>
<td width="201"><div align="right">nambre:</div></td>
<td width="199"><input type="text" name="nombre" /></td>
</tr>
<tr>
<td><div align="right">codigo:</div></td>
<td><input type="text" name="codigo" /></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><input type="submit" name="Submit" value="Enviar" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>
<?php
mysql_free_result($categoria);
?>

agredesco ante todo laayuda que puedadn brindarme..
Ricardo Cohen

  #2 (permalink)  
Antiguo 20/12/2007, 11:46
Avatar de kaninox  
Fecha de Ingreso: septiembre-2005
Ubicación: In my House
Mensajes: 3.597
Antigüedad: 18 años, 7 meses
Puntos: 49
Re: Problemas con header al hecer include!!

no puedes hacer un header(sprintf("Location: %s", $insertGoTo));
en ese lugar ya que tienes muchas entradas antes, recuerda que los headers son lo primero que se envian no pueden tener salidas antes de ellos
__________________
Gokuh Salvo al mundo. PUNTO!!!!
  #3 (permalink)  
Antiguo 20/12/2007, 11:46
Avatar de @ndreX!  
Fecha de Ingreso: abril-2007
Mensajes: 161
Antigüedad: 17 años
Puntos: 4
Re: Problemas con header al hecer include!!

Lo que yo hago en muchos casos, es redireccionar con JavaScript :) algo asi:

Código PHP:
if($_POST['enviar']){
     echo 
'<script>window.location=\'alguna-parte.php?con=valor&post='.$_POST['algo'].'\'</script>';

Espero te sirva... :)
  #4 (permalink)  
Antiguo 20/12/2007, 11:50
Avatar de ferbux  
Fecha de Ingreso: mayo-2007
Ubicación: por ahí intentado ayudar
Mensajes: 823
Antigüedad: 16 años, 11 meses
Puntos: 6
Re: Problemas con header al hecer include!!

Bienvenido rcohen:

prueba poner tus includes de tu parte html de esta forma:

Código:
{include file../includes/categ.php"}
ojala te ayude un poko.

saludos
__________________
"Eres grande por que caminas entre gigantes"
  #5 (permalink)  
Antiguo 20/12/2007, 11:59
Avatar de ferbux  
Fecha de Ingreso: mayo-2007
Ubicación: por ahí intentado ayudar
Mensajes: 823
Antigüedad: 16 años, 11 meses
Puntos: 6
Re: Problemas con header al hecer include!!

Intententa poner el header de esta forma:

Código:
 header("Location: ../ruta/alguna_ruta.php");
__________________
"Eres grande por que caminas entre gigantes"
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 12:18.