<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Codice per far commentare alcuni articoli]]></title><description><![CDATA[<p dir="auto">Salve ragazzi,</p>
<p dir="auto">utilizzo il seguente codice per far commentare alcuni articoli su un piccolo sito web; ultimamente mi hanno preso di mira con lo spam e vorrei inserire una domanda tipo quanto fa 2x3+1? ma non sono molto pratico qualcuno sa aiutarmi?</p>
<pre><code class="language-php">&lt;?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 = 3;
        // informazioni sulla locazione e sul nome del file di testo
    var $percorso_fisico_guest = "";
    var $guesttxt = "../comments/ed1.txt";
    var $nomefile;
        // larghezza in pixel della tabella esterna
    var $larghezza_tabella = "500";
        // 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-&gt;nomefile = $this-&gt;percorso_fisico_guest.$this-&gt;guesttxt;
        if (isset($_POST["indietro"]) || isset($_POST["avanti"])) {
            $this-&gt;posizione = $_POST["posizione"];
            $this-&gt;leggi_guestbook();
        } else {
            if (isset($_POST["azione"]) &amp;&amp; ($_POST["azione"] == "inserimento")) {
                $this-&gt;posizione = 0;
            } else {
                $this-&gt;leggi_guestbook();
                $this-&gt;posizione = 0;
            }
        }
    }
    // metodo per il calcolo della data
    function dataora_attuale() {
        $mesi = array("gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno", "luglio", "agosto", "settembre", "ottobre", "novembre", "dicembre");
        $mese = (int)date("m") - 1;
        $data = date("d")." ".$mesi[$mese]." ".date("Y");
        $ora = strftime ("%H:%M");
        $data_finale = $data." ore: ".$ora;
        return $data_finale;
    }
    // rimozione tag HTML
    function striptags($stringa) {
        $tag_consentiti = '&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;br&gt;';
        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-&gt;nomefile)) {
            echo '
                &lt;h2&gt;ERRORE:&lt;/h2&gt;
                Il file '.$this-&gt;nomefile.' non è presente su disco.&lt;br&gt;
                Createlo, anche vuoto, e riavviate lo script
            ';
            die;
        }
        $dimensione = filesize ($this-&gt;nomefile);
        if ($dimensione == 0) {
            $this-&gt;numero_righe = 0;
            return;
        }
        $this-&gt;book =  stripslashes(file_get_contents($this-&gt;nomefile));
        $this-&gt;righe = split($this-&gt;separatore_righe, $this-&gt;book);
        $this-&gt;righe = array_reverse($this-&gt;righe);
        $this-&gt;numero_righe = count($this-&gt;righe) - 1;
    }
    // metodo per mostrare un singolo record
    function mostra_record($indice) {
        list ($dataora, $nome, $email, $citta, $contatto, $commento) = split($this-&gt;separatore_campi, $this-&gt;righe[$indice]);
        $html_record = '&lt;table border="0" width="'.($this-&gt;larghezza_tabella-4).'" class="tabellaesterna"&gt;';
        $html_record .= '
            &lt;tr&gt;
                &lt;td&gt;
                    &lt;table border="0" width="'.($this-&gt;larghezza_tabella-20).'" cellspacing="1" cellpadding="4" class="tabellainterna"&gt;
                        &lt;tr&gt;
                            &lt;td width="100" align="left" class="intestazione"&gt;
                                inserito il:
                            &lt;/td&gt;
                            &lt;td align="left" class="testo"&gt;
                                '.$dataora.'
                            &lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td width="100" align="left" class="intestazione"&gt;
                                Nome:
                            &lt;/td&gt;
                            &lt;td align="left" class="testo"&gt;
                                '.$this-&gt;striptags($nome).'
                            &lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td width="100" align="left" class="intestazione"&gt;
                                e-mail:
                            &lt;/td&gt;
                            &lt;td align="left" class="testo"&gt;
                                '.$this-&gt;striptags($email).'
                            &lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td width="100" align="left" class="intestazione"&gt;
                                Città:
                            &lt;/td&gt;
                            &lt;td align="left" class="testo"&gt;
                                '.$this-&gt;striptags($citta).'
                            &lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td width="100" align="left" class="intestazione"&gt;
                                riferito da:
                            &lt;/td&gt;
                            &lt;td align="left" class="testo"&gt;
                                '.$this-&gt;striptags($contatto).'
                            &lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td width="100" align="left" class="intestazione" valign="top"&gt;
                                Commento:
                            &lt;/td&gt;
                            &lt;td align="left" class="testo" valign="top"&gt;
                                '.$this-&gt;striptags($commento).'
                            &lt;/td&gt;
                        &lt;/tr&gt;
                    &lt;/table&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
        ';
        $html_record .= '&lt;tr&gt;&lt;td&gt;&lt;a class="pulsanti" href="comments/ed1.php"&gt;torna alla lista&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;';
        $html_record .= '&lt;/table&gt;';
        return $html_record;
    }
    // metodo per gestire la visualizzazione della lista dei record con paginazione
    function mostra_lista() {
        if ($this-&gt;numero_righe == 0) {
            return "nessuno fin ora ha firmato il guestbook";
        }
        $limite = $this-&gt;record_per_pagina; // numero di record mostrati per pagina
        if (isset($_POST["indietro"])) { 
            $this-&gt;posizione--; 
            $inizio = $this-&gt;posizione*$limite;
        } else if (isset($_POST["avanti"])) { 
                $this-&gt;posizione++; 
                $inizio = $this-&gt;posizione*$limite;
            } else {    
                $inizio = 0;
            }
        $contatore = 0;
        $indice_riga = $inizio;
        $html_lista = '&lt;table border="0" width="'.($this-&gt;larghezza_tabella-4).'" class="tabellaesterna"&gt;';
        while (($indice_riga &lt; $this-&gt;numero_righe) &amp;&amp; ($contatore &lt; $limite)) {
            list ($dataora, $nome, $email, $citta, $contatto, $commento) = split($this-&gt;separatore_campi, $this-&gt;righe[$indice_riga]);
            if ($this-&gt;mostra_dettagli) {
                $dettagli = '&lt;a class="pulsanti" href="javascript: document.mostradettagli.indice.value=\''.$indice_riga.'\'; document.mostradettagli.submit()"&gt;dettagli&lt;/a&gt;';
            } else {
                $dettagli = '';
            }
            $html_lista .= '
                &lt;tr&gt;
                    &lt;td valign="top"&gt;
                        &lt;table border="0" width="'.($this-&gt;larghezza_tabella-26).'" cellspacing="0" cellpadding="4" class="tabellainterna" align="center"&gt;
                            &lt;tr&gt;
                                &lt;td width="100" align="left" class="intestazione"&gt;
                                    Nome:
                                &lt;/td&gt;
                                &lt;td align="left" class="testo"&gt;
                                    '.$this-&gt;striptags($nome).'
                                &lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td width="100" align="left" class="intestazione"&gt;
                                    Città:
                                &lt;/td&gt;
                                &lt;td align="left" class="testo"&gt;
                                    '.$this-&gt;striptags($citta).'
                                &lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td valign="top" width="100" align="left" class="intestazione"&gt;
                                    Commento:
                                &lt;/td&gt;
                                &lt;td valign="top" align="left" class="testo"&gt;
                                    '.ereg_replace("\n", "&lt;br&gt;", $this-&gt;striptags($commento)).'
                                &lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td align="left" width="100" valign="top" class="intestazione"&gt;
                                    '.$dettagli.'
                                &lt;/td&gt;
                                &lt;td align="right"&gt;
                                    '.$dataora.'
                                &lt;/td&gt;
                            &lt;/tr&gt;
                        &lt;/table&gt;
                    &lt;td&gt;
                &lt;/tr&gt;
            ';
            $contatore++;
            $indice_riga++;
        }
        $html_pulsanti = '';
        if ($this-&gt;numero_righe &gt; $limite) {
            if ($inizio &gt;=  $limite) {
                $html_pulsanti .= '&lt;input type="submit" value="&lt;&lt;" name="indietro" class="pulsanti"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;';
            }
            if ($indice_riga &lt; $this-&gt;numero_righe) {
                $html_pulsanti .= '&lt;input type="submit" value="&gt;&gt;" name="avanti" class="pulsanti"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;';
            }
        }
        $html_lista .= '
                    &lt;form method="post" action="comments/ed1.php" name="pageing"&gt;
            &lt;tr&gt;
                &lt;td&gt;
                        &lt;input type="hidden" value="mostralista" name="azione"&gt;
                        &lt;input type="hidden" name="posizione" value="'.$this-&gt;posizione.'"&gt;
                        '.$html_pulsanti.'
                &lt;/td&gt;
            &lt;/tr&gt;
                    &lt;/form&gt;
        ';
        $html_lista .= '
            &lt;/table&gt;
                    &lt;form method="post" action="comments/ed1.php" name="mostradettagli"&gt;
                        &lt;input type="hidden" value="dettagli" name="azione"&gt;
                        &lt;input type="hidden" name="indice" value=""&gt;
                    &lt;/form&gt;
            ';
        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-&gt;linea = $this-&gt;separatore_righe.$_POST["dataora"].$this-&gt;separatore_campi.$_POST["nome"].$this-&gt;separatore_campi.$_POST["email"].$this-&gt;separatore_campi.$_POST["citta"].$this-&gt;separatore_campi.$_POST["contatto"].$this-&gt;separatore_campi.$_POST["commento"]."\r\n";
            $puntatore = fopen($this-&gt;nomefile, "a");
            $this-&gt;linea = $this-&gt;striptags($this-&gt;linea);
            fputs($puntatore, $this-&gt;linea);
            fclose($puntatore);
        }
        $this-&gt;leggi_guestbook();
    }
    // metodo per la raccolta dati di un nuovo record
    function leggi_dati() {
        $html_form_immissione = '
            &lt;script language="JavaScript"&gt;
                &lt;!--
                    function controlla() {
                        if ((document.inseriscirecord.nome.value == \'\') || (document.inseriscirecord.commento.value == \'\')) {
                            alert(\'inserisci almeno il nome e un commento!\');
                            return false;
                        } else {
                            return true;
                        }
                    }
                //--&gt;
            &lt;/script&gt;
            &lt;form method="post" action="comments/ed1.php" name="inseriscirecord" onSubmit="return controlla();"&gt;
                  &lt;table border="0" width="'.($this-&gt;larghezza_tabella - 2).'" cellspacing="1" cellpadding="4" class="tabellainterna"&gt;
                    &lt;tr&gt;
                        &lt;td colspan="2" class="intestazione" width="'.($this-&gt;larghezza_tabella - 2).'"&gt;
                            Firma il nostro guestbook!
                        &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                        &lt;th align="left"&gt;
                            &amp;nbsp;nome: 
                        &lt;/th&gt;
                        &lt;td&gt;
                            &lt;input type="text" name="nome" size="40" class="areatesto"&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                        &lt;th align="left"&gt;
                            &amp;nbsp;e-mail: 
                        &lt;/th&gt;
                        &lt;td&gt;
                            &lt;input type="text" name="email" size="40" class="areatesto"&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                        &lt;th align="left"&gt;
                            &amp;nbsp;città: 
                        &lt;/th&gt;
                        &lt;td&gt;
                            &lt;input type="text" name="citta" size="40" class="areatesto"&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                        &lt;th align="left"&gt;
                            &amp;nbsp;riferito&lt;br&gt;
                            &amp;nbsp;da: 
                        &lt;/th&gt;
                        &lt;td&gt;
                            &lt;input type="text" name="contatto" size="40" class="areatesto"&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                        &lt;th align="left" valign="top"&gt;
                            &amp;nbsp;commenti: 
                        &lt;/th&gt;
                        &lt;td&gt;
                            &lt;textarea name="commento" rows="5" cols="45" class="areatesto"&gt;&lt;/textarea&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                        &lt;td colspan="2" class="intestazione"&gt;
                            &lt;input type="hidden" value="inserimento" name="azione"&gt;
                            &lt;input type="hidden" name="dataora" value="'.$this-&gt;dataora_attuale().'"&gt;
                            &lt;input type="submit" name="postati" value="vai !" class="pulsanti"&gt;
                            &lt;input type="reset" name="cancell" value="cancella" class="pulsanti"&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;    
                &lt;/table&gt;
            &lt;/form&gt;
        ';
        return $html_form_immissione;
    }
}
$guests = new guestbook();
if (isset($_POST["azione"]) &amp;&amp; ($_POST["azione"] == "inserimento")) {
    $guests-&gt;aggiungi_record();
} 
$html = "&lt;table&gt;&lt;tr&gt;&lt;td&gt;";
if (isset($_POST["azione"]) &amp;&amp; ($_POST["azione"] == "dettagli")) {
    $html .= $guests-&gt;mostra_record($_POST["indice"]);
} else {
    $html .= $guests-&gt;mostra_lista();
}
$html .= "&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;";
$html .= $guests-&gt;leggi_dati();
$html .= "&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;";
unset($guests);
?&gt;
&lt;!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt; Guestbook &lt;/title&gt;
&lt;meta name="Generator" content="Microsoft FrontPage 6.0"&gt;
&lt;meta name="Author" content=""&gt;
&lt;meta name="Keywords" content=""&gt;
&lt;meta name="Description" content=""&gt;
&lt;style&gt;
.tabellaesterna
{
    background-color: #B6C0CB;
    text-decoration: none;
    color: #FFFFFF;
    font-family: Verdana;
    font-size: 9pt;
    padding-top: 4pt;
    padding-right: 4pt;
    padding-bottom: 4pt;
    padding-left: 4pt;
    border-width: 2px;
    border-style: outset;
    empty-cells: show;
    font-weight: bold;
    margin: 0px;
}
.pulsanti
{
    background-color: #F8C152;
    font-family: Tahoma, Verdana;
    font-size: 8pt;
    font-weight: bold;
    font-style: normal;
    font-variant: normal;
    font-stretch: normal;
    color: #000080;
    border-width: 1px;
    border-style: outset;
    border-color: #6699CC;
    outline-style: double;
    outline-width: 1px;
    padding: 1px;
    margin: 1px;
    text-decoration: none;
}
.areatesto
{
    font-family: Verdana, Tahoma, Arial;
    font-size: 8pt;
    font-weight: normal;
    font-style: normal;
    font-variant: normal;
    font-stretch: normal;
    font-size-adjust: none;
    color: #000000;
    text-decoration: none;
    text-align: left;
    text-transform: none;
    vertical-align: middle;
    line-height: normal;
    word-spacing: normal;
    letter-spacing: normal;
    white-space: normal;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    margin-left: 0px;
    padding-top: 1px;
    padding-right: 1px;
    padding-bottom: 1px;
    padding-left: 1px;
    border-width: 1px;
    border-style: inset;
    border-color: #000000;
    outline-width: 0px;
    outline-style: none;
    background-color: #FFFFFF;
}
.tabellainterna
{
    background-color: #F2EEE3;
    text-decoration: none;
    color: #2D2E55;
    font-family: Verdana;
    font-size: 9pt;
    border-width: 1px;
    border-style: solid;
    border-color: #F8C152;
    margin: 0px;
    padding: 0px;
}
.intestazione
{
    background-color: #5E7FAA;
    color: #FFFFFF;
    font-style: normal;
    font-weight: bold;
    font-family: Verdana;
    font-size: 9pt;
}
.testo
{
    font-family: Tahoma;
    font-size: 9pt;
    background-color: #F4F4F4;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?=$html?&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
]]></description><link>https://dev.connect.gt/topic/62527/codice-per-far-commentare-alcuni-articoli</link><generator>RSS for Node</generator><lastBuildDate>Wed, 25 Nov 2026 10:22:03 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/62527.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 04 Feb 2008 16:26:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Codice per far commentare alcuni articoli on Wed, 06 Feb 2008 16:12:41 GMT]]></title><description><![CDATA[<p dir="auto">nessuno riesce a darmi una mano?</p>
]]></description><link>https://dev.connect.gt/post/679173</link><guid isPermaLink="true">https://dev.connect.gt/post/679173</guid><dc:creator><![CDATA[alexvs]]></dc:creator><pubDate>Wed, 06 Feb 2008 16:12:41 GMT</pubDate></item></channel></rss>