Codice PHP:
<?php
// le variabili si controllano con isset
if(isset($_POST['action']) && $_POST['action'] == "attach_msg") {
    
// a cosa serve se non riassegni ???
    // str_replace("\\", "\\\\", $_POST['msg']);
    // a cosa serve se non riassegni ???
    // htmlentities($_POST['msg'], ENT_QUOTES);
    
    // casomai ...
    
$_POST['msg'] = htmlentities(addslashes($_POST['msg']), ENT_QUOTES);
    
// comunque perche' addslashes ?

    
    
$fp fopen("messages.txt""a");
    
fwrite($fp"$_POST['name']|[--]|$_POST['msg']\n");
    
// e se mettessi nel testo o nel nome questo ? |[--]|

    
fclose($fp);

    
header("Location: index.php");
}
else{
    
$msg_db file("messages.txt");
    if(
count($msg_db) == && $msg_db[0] == "") {
        echo 
"non ci sono messaggi";
    }
    else{
        foreach(
$msg_db as $line) {
            if(
$line != "") {
                
$msg explode("|[--]|"$line);
                echo 
"
Messaggio inviato da: 
$msg[0]
$msg[1]";
            }
        }
    }
    echo 
"
Lascia un messaggio!
<form action='index.php' method='post'>
    Nome:<input type='text' name='name'>

    Messaggio:<textarea name='msg'></textarea>


    <input type='submit' value='Invia messaggio &gt;'>
    <input type='hidden' name='action' value='attach_msg'></form>"
;

// questo else non chiude ???
?>