HTML PHP文本框(简单?)

Intro: I've been wandering the internet trying to find a solution to no avail. I'm a PHP noob and my html and css are marginal.

Problem: I want to create a simple? text box on a website that can be edited and saved and displayed on the website.

If I could avoid PHP or other languages that would be fine but I think the save part is going to require some server site processing. Because I don't expect a large amount of data, storing the text boxes in a xml file or similar should be fine. (no need for a db)

I'm looking for the most simple and hopefully complete solution as I am a rookie with this stuff.

Notes: I should be able to copy and paste the html code anywhere to create more text/comment boxes. (maybe i need to change a ID or something that's fine)

I hope the comment box has no real text/character limits and any characters or quotes or html or other language is displayed as was written.

It cam be ugly, the focus is functional and simple.

I found this was closest to what I wanted but I could not get it working at all. Maybe its a language my computer or server was not happy with. LINK

Let's start by acknowledging that you will need PHP, and unless you have a proper login system or alternatively a CAPTCHA, this project can be prone to a bot that floods a bunch of messages - I know from experience. All you need to make is an HTML form which will be used to type and submit the text to this public "bulletin board":

<form method='post' action='http://yoursite/newmessage.php' type='submit'>
    <input type='text' name='text' placeholder="Type message here"/>
    <input type='submit' value='Submit' />
</form>

This form will send whatever the user types in the text input to a PHP file, which will then save it. Now, for something very simple like this you can or cannot use a database.

Benefits of a database:

  1. More secure
  2. If two people try to add a message simultaneously, less issues there

Benefits of a text file

  1. Much simpler to make

Since you are not storing any personal data, a text file will be fine. You can name this whatever you want on the server - it doesn't matter. This will be the PHP file:

<?php
    $newText = $_REQUEST['text']; //data submitted from HTML form
    $currentText = file_get_contents('data.txt'); //txt file in same folder as this PHP file_get_contents
    $concatText = $currentText . '<div><p>' . $newText . '</p></div>';
    file_put_contents('data.txt',$concatText);
?>

Lastly, displaying the data on the HTML page is easy. First make sure you are running this on a server that executes PHP, and it'd help to rename index.html to index.php:

<?php
    $all_data = file_get_contents('data.txt');
    echo $all_data;
?>

Edit I just saw that you want it password-protected. Simply create another text input in the form and in PHP verify that it matches a string.