Below is the
PHP code. The guestbook data is stored in guestbook.txt. For the
ASP code, go to the next page.
guestbook.php
//If data is submitted
If (isset($submit)){
if ($submit=="Y"){
$datestamp =(date ("dS F Y ( h:i:s A )",time())); //current
date
$fpn=@fopen("guestbook.txt","a+"); //open guest book
txt for append mode.
@flock ($fpn,2);
$rec = "Name: <b>$txtname</b><br>Email:
<b><u><a href=\"mailto:$txtemail\">$txtemail</a></u></b><br>Website:
<b><u><a href=\"$txtwebsite\" target=\"_blank\">$txtwebsite</a></u></b><br>Comments:
<b>$txtcomments</b><br><i>Posted on: $datestamp" . "\n";
// store data in HTML format
$fw=fwrite($fpn,$rec);
@flock($fpn,3);
@fclose($fpn);
}
}
//Read Data from Guest Book Database
//Store all entries in a Array.
$fp=@fopen("guestbook.txt","r");
@flock ($fp,2);
$garr=array();
while ($line=@fgets($fp,1024)){
array_push($garr,$line);
}
$totalent=count($garr)-1;
if ($totalent<0){
$totalent=0;
}
if($highlimit>$totalent){
$highlimit=$totalent;
}
//Following code will be used for sending variables to PHP script.
print "&txtll=$lowlimit&txthl=$highlimit&totalentries=$totalent&txtmain=" ;
//If u remember txtll,txthl,totalentries and txtmain are dyanamic text boxes
we have created in flash movie.
if (count($garr)==0){
print "<br><br><b> :::: Nothing to display ::::
</b>";
exit();
}
$ar=array_reverse($garr); // reverse the array
$garr=array();
for($i=$lowlimit;$i<=$highlimit;$i++){ // filter the records between lowlimit
and highlimit
if (!$ar[$i]) {
print "<br><br><b>::: Nothing Below This :::</b>";
exit;
}
print $ar[$i];
print "<br><br>";
}
@flock($fp,3);
@fclose($fp);
Comments