//使用正则表达式除去用户填写的一些非法字符
$Email = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Email);
$Website = eregi_replace("http://", "", $Website);
$Website = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\~\:]", "", $Website);
$Name = stripslashes($Name);
$Email = stripslashes($Email);
$Website = stripslashes($Website);
$Comments = stripslashes($Comments);
//将用户新填写的记录存入文本文件,以及从文本文件中读取信息
if ($Submit == "Yes") {
//指定了文本文件的文件名
$filename = "GuestBook.txt";
//产生一个操作该文件的句柄
$fp = fopen( $filename,"r");
$OldData = fread($fp, 80000);
fclose( $fp );
//获得用户提交信息时的时间
$Today = (date ("Y-m-d H:i:s",time()));
#Puts the recently added data into html format that can be read into the Flash Movie.
$Input = "姓名: $Name
Email: $Email
主页: $Website
留言: $Comments
发表时间: $Today
.:::.";
#This Line adds the 'GuestBook=' part to the front of the data that is stored in the text file. This is important because without this the Flash movie would not be able to assign the variable 'GuestBook' to the value that is located in this text file
$New = "$Input$OldData";
#Opens and writes the file.
$fp = fopen( $filename,"w+");
fwrite($fp, $New, 80000);
fclose( $fp );
}
####################################################################################
########## Formatting and Printing the Data from the Guestbook to the Flash Movie ##
#Next line tells the script which Text file to open.
$filename = "GuestBook.txt";
#Opens up the file declared above for reading
$fp = fopen( $filename,"r");
$Data = fread($fp, 80000);
fclose( $fp );
#Splits the Old data into an array anytime it finds the pattern .:::.
$DataArray = split (".:::.", $Data);
#Counts the Number of entries in the GuestBook
$NumEntries = count($DataArray) - 1;
print "&TotalEntries=$NumEntries&NumLow=$NumLow&NumHigh=$NumHigh&GuestBook=";
for ($n = $NumLow; $n < $NumHigh; $n++) {
print $DataArray[$n];
if (!$DataArray[$n]) {
Print "
没有更多的留言了!";
exit;
}
}
####################################################################################
############### End GuestBook Script
?>