PDA

View Full Version : I programmed a php guestbook!!!



Archbob
September 14th, 2002, 21:49
I can't believe it, I wrote a guestbook in php, I am so proud of myself. Thanks to the people of freewebspace and phpbuilders for help. Check it out:
http://www.granulomata.com/partyofthegood/guestbook/index.php

Aren't you guys amazed?

Daniel
September 14th, 2002, 22:03
Good job. ;)


And I signed it. :D

Archbob
September 14th, 2002, 22:22
Ack! I need to fix it where newer entries go on top of old ones.

Daniel
September 14th, 2002, 22:33
You deleted my post. :crysad:

Archbob
September 14th, 2002, 23:02
Sorry, my mistake, I tried to change it so that newer entries would come on top and I changed 'a' to 'w' so my test entry overwrote all the earlier ones. I can't figure out how to make it work right!!

Dusty
September 14th, 2002, 23:22
You can't write to the beginning of a file-- not only can't you in PHP, but you can't in any language I'm aware of. You'll need to read the contents of the file, store them somewhere, overwrite the file beginning with the new line you want to add, then write back what you took from the file before you deleted it. You could just store the file in a variable, but if the file is a large one you'll be wasting tremendous amounts of memory that way. A better way would be to copy the file's contents to a temporary file, overwrite the file with the new line, then copy, line-by-line, the temporary file into the file, and end by deleting the temporary file. That way's memory efficient, no more than one line is used at a time and no unnecessary data is stored, but it does take slightly more time and uses more of the CPU. Still, I'd do that before dumping the whole file into an array, unshifting a new element to the beginning, and writing the file back out-- that's just wasteful. Of course, if it's only a small file it doesn't matter, but a guestbook does have the potential of growing very large.

Archbob
September 15th, 2002, 00:36
Umm, nevermind, I'm trying to make modification, the guestbook doesn't work anymore.

YUPAPA
September 15th, 2002, 01:26
You can use a database to sort all the records! from newest to oldest!

Archbob
September 15th, 2002, 01:28
I don't have a spare database on hand so I'm trying to work with arrays.

hohoho
September 15th, 2002, 03:45
and here is mine...programmed in about 5min :D
http://miami.dnsvault.com/~sound/mitja/gb/index.php
text file based :cool: