<?php $date = date( "l, F j Y, h:i a"); if ($homepage == "" || $email == "" || $name == "" || $comments == "") { //error checking header("Location: guestbook.html"); exit; } $message .="Name: $name \n"; $message .="Email: <a href=\"mailto:$email\">$email</a> \n"; $message .="Homepage: <a href=\"$homepage\">$homepage</a> \n"; $message .="Comments: $comments \n"; $message .="Date: $date \n"; $message .="----------------------------- \n"; if ($message){ // first read the file into a buffer, if it exists // open in read mode only if ($fp = @fopen ("guestbook.data", "r")){ $oldmessages = @fread($fp,filesize("guestbook.data")); @fclose(fp); } // now reopen the file in write mode, with the // pointer at the head of the file $fp = fopen ("guestbook.data", "w"); fwrite ($fp, $message); fwrite ($fp, $oldmessages); // adding back the old messages fclose ($fp); } if (file_exists("guestbook.data")){ Header("Location: viewguestbook.html"); } ?>