";
$submitAction = isset($_POST['submit']);
$formNote = $_POST['note'];
$formName = $_POST['name'];
$formEmail = $_POST['email'];
$formURL = $_POST['url'];
if ($submitAction) {
$tmpfile = "guestbook_entries.tmp";
$lockfile = "guestbook_entries.lck";
// get actual time/date
$timeStamp = date("d.m.y @ H:i");
$fhLock = fopen($lockfile,"w+") or die ("cannot open lockfile");
flock($fhLock, LOCK_EX) or die ("cannot lock lockfile");
if (!file_exists($GUESTBOOK_ENTRIES_FILENAME)) {
echo ("recreating guestbook entries file");
touch("$GUESTBOOK_ENTRIES_FILENAME");
}
$fhArch = fopen($GUESTBOOK_ENTRIES_FILENAME,"r") or die ("cannot open archfile");
$fhTemp = fopen($tmpfile,"w+") or die ("cannot create tmpfile");
while (!feof($fhArch)) {
$line = fgets($fhArch,$BUFSIZE);
#$line=substr($line,0,-1); // cutoff last character (\n)
fwrite($fhTemp,$line);
if (eregi("^$INSERT_TAG", $line)) {
if (strlen($formNote) > 0) {
fwrite($fhTemp,$formNote."\n");
fwrite($fhTemp,"
\n");
if (strlen($formEmail) > 0) {
fwrite($fhTemp,"$formName $timeStamp\n");
} else {
fwrite($fhTemp,"$formName $timeStamp\n");
}
if (strlen($formURL) > 0) {
if (!eregi("^http://",$formURL)) {
$formURL = "http://".$formURL;
}
fwrite($fhTemp," ($formURL)\n");
}
fwrite($fhTemp,"
\n");
}
}
}
fclose ($fhArch);
fclose ($fhTemp);
unlink($GUESTBOOK_ENTRIES_FILENAME);
rename ($tmpfile, $GUESTBOOK_ENTRIES_FILENAME);
flock($fhLock, LOCK_UN);
fclose ($fhLock);
unlink($lockfile);
}
?>
|
|