Classic Guestbook made with Flash and ASP/PHP

The PHP Code

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);

You might also like...

Comments

About the author

Pradeep Mamgain India

Woking as a VB programmer. Use my free type in writing code and maintaining my site. I have an exclusive collection of PHP stuff for windows at my site.

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If debugging is the process of removing software bugs, then programming must be the process of putting them in.” - Edsger Dijkstra