Here's an example in PHP. First, the form (put this in somefile.html):
Name: <input name="n" value=""> <br>
<input type="submit" value="Send string to server"> </form>
print("oops! webmaster you need to create that file first");
print("webmaster you need to add write permissions to file");
$f = fopen("nameList.txt", "a"); // a is for append or "add to end of"
fwrite($f, $n); // $n is from our form!
print("For some reason we couldn't open that file");
print("get ready to see the contents of the file<hr><pre>");
readfile("nameList.txt"); // just spits out the contents of the file
What we've done is not very good practice because the page
we produced is very poorly formed HTML. Secondly, we didn't
check to see how big the data in $n was, or if there was any
at all. Sloppiness like that can get you in trouble with the
script kiddies who want to screw up your website.
Lastly, the data format for our file is very unstructured. We could improve this by adding an end line character after each new name. This would be the equivalent of hitting the return key after each name in a text document. Since there is no agreed-upon symbol for return key, programming languages use \n as the two-character symbol for endline. So we would amend our script to say fwrite($f, "$n \n");