Posted February 7 '10 at 10:42 PM
Posts: 3
<?php
function readMyFile(){
$fp=fopen('./textfile.txt','r');
echo fread($fp,filesize('./textfile.txt'));
fclose($fp);
}
function writeMyFile($str){
$fp=fopen('./textfile.txt','a');
fwrite($fp,$str);
fclose($fp);
}
$message=$_GET['message'];
if($message<>NULL){
writeMyFile($message);
}else{
readMyFile();
}
?>
Make sure the web-server user can write to the 'textfile.txt' file. The script returns the contents of the file by default or appends a users message to the file if a message is sent.
Using a flat-file as a database is very slow compaired to using a MySQL database and is harder to control and update.