Qui c'è tutto il codice php della mia pagina . il file di testo su cui vengono scritto i messaggi si chiama guests.txt. Spero ke serva darti tutto il codice...



Codice PHP:
<?php
/*
Text Guestbook
script per gestire un libro degli ospiti utilizzando un file di testo
data: 31 maggio 2005
Autore: Michele Bracci
Potete distribuire questo script per usi non commerciali e modificarlo 
come desiderate. Vi prego di citare sempre l'autore originale e di
evidenziare e firmare eventuali modifiche. Grazie.
*/
class guestbook {
    
// parametri
    
var $separatore_righe "--inizioriga--";
    var 
$separatore_campi "--finecampo--";
        
// numero di record mostrato per pagina: è possibile modificare questo valore a vostro piacimento
    
var $record_per_pagina 10;
        
// informazioni sulla locazione e sul nome del file di testo
    
var $percorso_fisico_guest "";
    var 
$guesttxt "guests.txt";
    var 
$nomefile;
        
// larghezza in pixel della tabella esterna
    
var $larghezza_tabella "670";
        
// settando questa opzione a vero, il visitatore potrà visualizzare i dettagli di un singolo record
    
var $mostra_dettagli true;
    
// caratteristiche del guestbook
    
var $righe = array();
    var 
$posizione;
    var 
$numero_righe;
    var 
$book;
    var 
$linea;
    
// COSTRUTTORE
    
function guestbook() {
        
$this->nomefile $this->percorso_fisico_guest.$this->guesttxt;
        if (isset(
$_POST["indietro"]) || isset($_POST["avanti"])) {
            
$this->posizione $_POST["posizione"];
            
$this->leggi_guestbook();
        } else {
            if (isset(
$_POST["azione"]) && ($_POST["azione"] == "inserimento")) {
                
$this->posizione 0;
            } else {
                
$this->leggi_guestbook();
                
$this->posizione 0;
            }
        }
    }
    
// metodo per il calcolo della data
    
function dataora_attuale() {
        
$mesi = array("january""febraur""march""april""may""june""july""august""september""october""november""december");
        
$mese = (int)date("m") - 1;
        
$data date("d")." ".$mesi[$mese]." ".date("Y");
        
$ora strftime ("%H:%M");
        
$data_finale $data." - time ".$ora;
        return 
$data_finale;
    }
    
// rimozione tag HTML
    
function striptags($stringa) {
        
$tag_consentiti '[b][i]<u>
'
;
        return 
strip_tags($stringa$tag_consentiti );
    }
    
// metodo per leggere il file di testo. Verrà memorizzato nella caratteristica $book
    
function leggi_guestbook() {
        if (!
file_exists($this->nomefile)) {
            echo 
'
                <h2>ERRORE:</h2>
                Il file '
.$this->nomefile.' non è presente su disco.

                Createlo, anche vuoto, e riavviate lo script
            '
;
            die;
        }
        
$dimensione filesize ($this->nomefile);
        if (
$dimensione == 0) {
            
$this->numero_righe 0;
            return;
        }
        
$this->book =  stripslashes(file_get_contents($this->nomefile));
        
$this->righe split($this->separatore_righe$this->book);
        
$this->righe array_reverse($this->righe);
        
$this->numero_righe count($this->righe) - 1;
    }
    
// metodo per mostrare un singolo record
    
function mostra_record($indice) {
        list (
$dataora$nome$email$citta$contatto$commento) = split($this->separatore_campi$this->righe[$indice]);
        
$html_record '<table border="0" width="'.($this->larghezza_tabella-4).'" class="tabellaesterna">';
        
$html_record .= '
            <tr>
                <td>
                    <table border="0" width="'
.($this->larghezza_tabella-20).'" cellspacing="1" cellpadding="4" class="tabellainterna">
                        <tr>
                            <td width="100" align="left" class="intestazione">
                                date:
                            </td>
                            <td align="left" class="testo">
                                '
.$dataora.'
                            </td>
                        </tr>
                        <tr>
                            <td width="100" align="left" class="intestazione">
                                name:
                            </td>
                            <td align="left" class="testo">
                                '
.$this->striptags($nome).'
                            </td>
                        </tr>
                        <tr>
                            <td width="100" align="left" class="intestazione">
                                e-mail:
                            </td>
                            <td align="left" class="testo">
                                '
.$this->striptags($email).'
                            </td>
                        </tr>
                        <tr>
                            <td width="100" align="left" class="intestazione">
                                location:
                            </td>
                            <td align="left" class="testo">
                                '
.$this->striptags($citta).'
                            </td>
                        </tr>
                        
                        <tr>
                            <td width="100" align="left" class="intestazione" valign="top">
                                comment:
                            </td>
                            <td align="left" class="testo" valign="top">
                                '
.$this->striptags($commento).'
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        '
;
        
$html_record .= '<tr><td>[url="guestbook.php"]back[/url]</td></tr>';
        
$html_record .= '</table>';
        return 
$html_record;
    }
    
// metodo per gestire la visualizzazione della lista dei record con paginazione
    
function mostra_lista() {
        if (
$this->numero_righe == 0) {
            return 
"nessuno fin ora ha firmato il guestbook";
        }
        
$limite $this->record_per_pagina// numero di record mostrati per pagina
        
if (isset($_POST["indietro"])) { 
            
$this->posizione--; 
            
$inizio $this->posizione*$limite;
        } else if (isset(
$_POST["avanti"])) { 
                
$this->posizione++; 
                
$inizio $this->posizione*$limite;
            } else {    
                
$inizio 0;
            }
        
$contatore 0;
        
$indice_riga $inizio;
        
$html_lista '<table border="0" width="'.($this->larghezza_tabella-4).'" class="tabellaesterna">';
        while ((
$indice_riga $this->numero_righe) && ($contatore $limite)) {
            list (
$dataora$nome$email$citta$contatto$commento) = split($this->separatore_campi$this->righe[$indice_riga]);
            if (
$this->mostra_dettagli) {
                
$dettagli '[url="javascript: document.mostradettagli.indice.value=\''.$indice_riga.'\'; document.mostradettagli.submit()"]details[/url]';
            } else {
                
$dettagli '';
            }
            
$html_lista .= '
                <tr>
                    <td valign="top">
                        <table border="0" width="'
.($this->larghezza_tabella-26).'" cellspacing="0" cellpadding="4" class="tabellainterna" align="center">
                            <tr>
                                <td width="100" align="left" class="intestazione">
                                    name:
                                </td>
                                <td align="left" class="testo">
                                    '
.$this->striptags($nome).'
                                </td>
                            </tr>
                            <tr>
                                <td width="100" align="left" class="intestazione">
                                    location:
                                </td>
                                <td align="left" class="testo">
                                    '
.$this->striptags($citta).'
                                </td>
                            </tr>
                            <tr>
                                <td valign="top" width="100" align="left" class="intestazione">
                                    comment:
                                </td>
                                <td valign="top" align="left" class="testo">
                                    '
.ereg_replace("\n""
"
$this->striptags($commento)).'
                                </td>
                            </tr>
                            <tr>
                                <td align="left" width="100" valign="top" class="intestazione">
                                    '
.$dettagli.'
                                </td>
                                <td align="right">
                                    '
.$dataora.'
                                </td>
                            </tr>
                        </table>
                    <td>
                </tr>
            '
;
            
$contatore++;
            
$indice_riga++;
        }
        
$html_pulsanti '';
        if (
$this->numero_righe $limite) {
            if (
$inizio >=  $limite) {
                
$html_pulsanti .= '<input type="submit" value="<<" name="indietro" class="pulsanti">';
            }
            if (
$indice_riga $this->numero_righe) {
                
$html_pulsanti .= '<input type="submit" value=">>" name="avanti" class="pulsanti">';
            }
        }
        
$html_lista .= '
                    <form method="post" action="guestbook.php" name="pageing">
            <tr>
                <td>
                        <input type="hidden" value="mostralista" name="azione">
                        <input type="hidden" name="posizione" value="'
.$this->posizione.'">
                        '
.$html_pulsanti.'
                </td>
            </tr>
                    </form>
        '
;
        
$html_lista .= '
            </table>
                    <form method="post" action="guestbook.php" name="mostradettagli">
                        <input type="hidden" value="dettagli" name="azione">
                        <input type="hidden" name="indice" value="">
                    </form>
            '
;
        return 
$html_lista;
    }
    
// Metodo per l'inserimento di un nuovo record
    
function aggiungi_record() {
        
$test_non_vuoto trim($_POST["nome"].$_POST["email"].$_POST["citta"].$_POST["contatto"].$_POST["commento"]);
        if (
$test_non_vuoto != "") {
            
$this->linea $this->separatore_righe.$_POST["dataora"].$this->separatore_campi.$_POST["nome"].$this->separatore_campi.$_POST["email"].$this->separatore_campi.$_POST["citta"].$this->separatore_campi.$_POST["contatto"].$this->separatore_campi.$_POST["commento"]."\r\n";
            
$puntatore fopen($this->nomefile"a");
            
$this->linea $this->striptags($this->linea);
            
fputs($puntatore$this->linea);
            
fclose($puntatore);
        }
        
$this->leggi_guestbook();
    }
    
// metodo per la raccolta dati di un nuovo record
    
function leggi_dati() {
        
$html_form_immissione '
            <script language="JavaScript">
                <!--
                    function controlla() {
                        if ((document.inseriscirecord.nome.value == \'\') || (document.inseriscirecord.commento.value == \'\')) {
                            alert(\'inserisci almeno il nome e un commento!\');
                            return false;
                        } else {
                            return true;
                        }
                    }
                //-->
            </script>
            <form method="post" action="guestbook.php" name="inseriscirecord" onSubmit="return controlla();">
                  <table border="0" width="'
.($this->larghezza_tabella 2).'" cellspacing="1" cellpadding="4" class="tabellainterna">
                    <tr>
                        <td colspan="2" class="intestazione" width="'
.($this->larghezza_tabella 2).'">
                            sign our guestbook
                        </td>
                    </tr>
                    <tr>
                        <th align="left">
                            name: 
                        </th>
                        <td>
                            <input type="text" name="nome" size="40" class="areatesto">
                        </td>
                    </tr>
                    <tr>
                        <th align="left">
                            e-mail: 
                        </th>
                        <td>
                            <input type="text" name="email" size="40" class="areatesto">
                        </td>
                    </tr>
                    <tr>
                        <th align="left">
                            location: 
                        </th>
                        <td>
                            <input type="text" name="citta" size="40" class="areatesto">
                        </td>
                    </tr>
                    
                    <tr>
                        <th align="left" valign="top">
                            comment: 
                        </th>
                        <td>
                            <textarea name="commento" rows="10" cols="45" class="areatesto"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" class="intestazione">
                            <input type="hidden" value="inserimento" name="azione">
                            <input type="hidden" name="dataora" value="'
.$this->dataora_attuale().'">
                            <input type="submit" name="postati" value="submit" class="pulsanti">
                            <input type="reset" name="cancell" value="reset" class="pulsanti">
                        </td>
                    </tr>    
                </table>
            </form>
        '
;
        return 
$html_form_immissione;
    }
}
$guests = new guestbook();
if (isset(
$_POST["azione"]) && ($_POST["azione"] == "inserimento")) {
    
$guests->aggiungi_record();

$html "<table><tr><td>";
if (isset(
$_POST["azione"]) && ($_POST["azione"] == "dettagli")) {
    
$html .= $guests->mostra_record($_POST["indice"]);
} else {
    
$html .= $guests->mostra_lista();
}
$html .= "</td></tr><tr><td>";
$html .= $guests->leggi_dati();
$html .= "</td></tr></table>";
unset(
$guests);
?>