Ver Mensaje Individual
  #4 (permalink)  
Antiguo 24/01/2004, 14:32
josemi
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.