PDA

View Full Version : Guestbook problems



Didiusthegreat
January 6th, 2004, 02:16 PM
Has anybody ever tried the guestbook tutorial on flash-db?

I tried it, but I have some questions.


<?php
// If you are using an old version of php, remove the next set of lines.
// or use $HTTP_POST_VARS["..."] instead.
$Submit = $_POST["Submit"];
$Name = $_POST["Name"];
$Email = $_POST["Email"];
$Website = $_POST["Website"];
$Comments = $_POST["Comments"];
$NumLow = $_REQUEST["NumLow"];
$NumHigh = $_REQUEST["NumHigh"];

// Replace special characters - you can remove the next 5 lines if wanted.

// Remove slashes.
$Name = stripslashes($Name);
$Email = stripslashes($Email);
$Website = stripslashes($Website);
$Comments = stripslashes($Comments);

// ################################################## #################################
// ########## Reading and Writing the new data to the GuestBook Database #############

if ($Submit == "Yes") {
// 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");
$OldData = fread($fp, 80000);
fclose( $fp );

// Gets the current Date of when the entry was submitted
$Today = (date ("l dS of F Y ( h:i:s A )",time()));

// Puts the recently added data into html format that can be read into the Flash Movie.
// You can change this up and add additional html formating to this area. For a complete listing of all html tags
// you can use in flash - visit: http://www.macromedia.com/support/flash/ts/documents/htmltext.htm

$Input = "<b>Naam:</b> $Name<br><b>Email: </b><a href=\"mailto:$Email\">$Email </a><br><b>Website: </b><a href=\"http://$Website\" target=\"_blank\">$Website</a><br><b>Comments: </b>$Comments<br><br>.:::.";

/* 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");
if(!$fp) die("&GuestBook=cannot write $filename ......&");
fwrite($fp, $New, 800000);
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, 800000);
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 "<br><br><b>No More entries</b>";
exit;
}
}
?>


The thing I don't understand



$fp = fopen( $filename,"r");
$Data = fread($fp, 800000);
fclose( $fp );


Can someone explain this code? What's the 800000 for?
I really get stuck on this bit.

Didiusthegreat
January 6th, 2004, 02:40 PM
Could someone explain me this to?


NumLow = 0;
NumHigh = 10;
loadVariablesNum ("GuestBook.php?NumLow="+NumLow+"&NumHigh="+NumHigh+"&R="+random(999), 0);
stop();

That is found in the flash file

Why is the random(999) there?

λ
January 6th, 2004, 02:55 PM
random(999) stops the Flash Player from caching the script.

the earlier snippet opens the file $filename, reads a line of text 80000 bytes long from the file, and closes the file.

kill.robot.kill
January 6th, 2004, 04:38 PM
taken from php.net
fread ( resource handle, int length)

fread() reads up to length bytes from the file pointer referenced by handle. Reading stops when length bytes have been read, EOF (end of file) is reached, or (for network streams) when a packet becomes available, whichever comes first.

...basically what njs12345 wrote :)

Didiusthegreat
January 7th, 2004, 08:06 AM
Thnx, I understand it more now


cheers :}