Click to See Complete Forum and Search --> : Guestbook


Jonathan
06-10-2003, 01:48 AM
I need a banner free guestbook with no links to other pages, just mine. So if anyone knows of a guestbook script let me know.. maybe i should ask PHP, but i need a guestbook... maybe a generator would be better.

pyro
06-10-2003, 07:15 AM
Here's a simple guestbook. It shouldn't be too hard to change the way it looks.... You can see it at http://www.infinitypages.com/temp/guestbook.php

You will need a file named guestbook.txt CHMODed to 666 (read/writeable).

<?PHP

$filename = "guestbook.txt"; #CHMOD to 666
$text = "";

if (isset($_POST["submit"])) {
$name = htmlspecialchars($_POST["name"]);
$message = htmlspecialchars($_POST["message"]);

$date = date ("l, F jS, Y");
$time = date ("h:i A");

$value = $message."<br>\n<span style=\"font-family: verdana, arial, sans-serif; font-size: 70%; font-weight: bold;\">Posted by $name at $time on $date.</span>\n<break>\n";

##Write the file##

$fp = fopen ($filename, "a");
if ($fp) {
fwrite ($fp, $value);
fclose ($fp);
}
else {
echo ("Your entry could not be added.");
}
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Guestbook</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="<?PHP echo $_SERVER["PHP_SELF"]; ?>" method="post">
<p>Your Message:<br>
<textarea name="message" rows="7" cols="50"></textarea><br>
Your Name: <input type="text" name="name">
<input type="submit" name="submit" value="submit"></p>
</form>

<?PHP

$contents = @file($filename) or die("No files in guestbook.");

foreach ($contents as $line_num => $line) {
$text .= $line;
}

$text = split("<break>", $text);

for ($i=0; $i<count($text)-1; $i++) {
echo "<div style=\"border: gray 1px solid; padding: 5px; font-family: arial, sans-serif; background-color: #eeeeee;\">";
echo $text[$i];
echo "</div>";
}

?>
</body>
</html>

Jonathan
06-10-2003, 11:27 AM
What do I need to type in the Guestbook.txt and what is the CHMOD thing... not familiar...

pyro
06-10-2003, 11:33 AM
You don't type anything in guestbook.txt... just upload the blank file. To CHMOD, you will need to FTP to your site, and check the documentation on how to CHMOD files...

Jonathan
06-10-2003, 11:35 AM
So do I make the CHMOD blank and with notepad? Can you tall me how to create one
?

pyro
06-10-2003, 11:44 AM
No, sorry. Let me explain what CHMOD is. CHMOD is the Unix/Linux way to change the permissions of a file. Basically, it is just a Unix command to tell the file to be able to be written to.

Anyway, the script should create the file if it does not exist, so try just running guestbook.php without even uploading guestbook.txt... It should create it for you.

Jonathan
06-10-2003, 11:47 AM
So I don't have to do anything, just copy&paste the php script into a "Guestbook.php"...
Are you sure.. how will it keep track of the signatures?

brendandonhue
06-11-2003, 03:12 PM
It will save them in guestbook.txt.
Are you sure your server supports PHP?

Dark Dragon
10-14-2003, 02:01 PM
I am a bit confused as well.

This code you gave Pyro, I copied it into notepad...so can I just upload that notepad file into my host directory then as well as the blank guestbook.txt file?

Or do I need to paste the code you gave us onto a web page document then save it? I know this sounds painfully simple but I am unfamiliar with PHP.

Secondly if I do have to paste the code into a web page document..do I have to save it as a PHP or just save it as I would any other web page?

Thanks.

pyro
10-14-2003, 02:12 PM
Basically what you do is take all the code in the PHP block above and copy it into any HTML/plain text editor. Then, save the file with a .php extention (for PHP to be processed, it must have a .php extention). So yes, just copy the code into notepad, and save with a .php extention. Now, make a .txt file named guestbook.txt and upload that to the server as well. Once it is on the server, CHMOD the guestbook.txt file to 666 (so the PHP script can write to it).

Dark Dragon
10-14-2003, 02:15 PM
Oh..okay..that sounds easy enough. Thanks Pyro!

Dark Dragon
10-14-2003, 02:23 PM
Okay..here is another inquery..I would like the newest entry to appear at the top..what do I need to alter in order to make this happen?

Please keep in mind I am a complete idiot when it comes to PHP so don't get too techy on me. :D

pyro
10-14-2003, 03:06 PM
Ok, try changing the ##Write the file## section to look like this (untested):

##Read old file##

$contents = @file($filename);
$file = "";
foreach ($contents as $line) {
$file .= $line;
}

$post = $file.$value;

##Write the file##

$fp = fopen ($filename, "w");
if ($fp) {
flock($fp, LOCK_EX);
fwrite ($fp, $post);
flock($fp, LOCK_UN);
fclose ($fp);
}
else {
echo ("Your entry could not be added.");
}

Dark Dragon
10-14-2003, 04:16 PM
Thanks Pyro..I am gonna try that then

Here is what I have so far..tell me if this looks correct please.

P.S..I altered the background color and text color..so that is why there is CSS.

<?PHP

$filename = "guestbook.txt"; #CHMOD to 666
$text = "";

if (isset($_POST["submit"])) {
$name = $_POST["name"];
$message = $_POST["message"];

$date = date ("l, F jS, Y");
$time = date ("h:i A");

$value = $message."<br>\n<span style=\"font-family: verdana, arial, sans-serif; font-size: 70%; font-weight: bold;\">Posted by $name at $time on $date.</span>\n<break>\n";
##Read old file##

$contents = @file($filename);
$file = "";
foreach ($contents as $line) {
$file .= $line;
}

$post = $file.$value;

##Write the file##

$fp = fopen ($filename, "w");
if ($fp) {
flock($fp, LOCK_EX);
fwrite ($fp, $post);
flock($fp, LOCK_UN);
fclose ($fp);
}
else {
echo ("Your entry could not be added.");
}

}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Guestbook</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
body {background-color: rgb(24,24,24)}
</style>
</head>

<body text="#FFFFFF">
<form action="<?PHP echo $_SERVER["PHP_SELF"]; ?>" method="post">
<p>Your Message:<br>
<textarea name="message" rows="7" cols="50"></textarea><br>
Your Name: <input type="text" name="name">
<input type="submit" name="submit" value="submit"></p>
</form>

<?PHP

$contents = @file($filename) or die("No files in guestbook.");

foreach ($contents as $line_num => $line) {
$text .= $line;
}

$text = split("<break>", $text);

for ($i=0; $i<count($text)-1; $i++) {
echo "<div style=\"border: blue 1px solid; padding: 5px; font-family: arial, sans-serif; background-color: #000000;\">";
echo $text[$i];
echo "</div>";
}

?>
</body>
</html>

pyro
10-14-2003, 05:22 PM
Yeah, it looks good -- does it work for you?

Dark Dragon
10-14-2003, 05:24 PM
I haven't really tried it yet..I suppose I need to upload it first don't I?

P.S..Thanks for the help Pyro...appreciate it...wish I had learned this in business college ;)

pyro
10-14-2003, 05:25 PM
hehe... sure thing, man... :)

Dark Dragon
10-14-2003, 05:31 PM
Well..I uploaded it but I cannot view it.

Of course I got a site on Yahoo Geocities..so maybe that is the problem...I uploaded the PHP page but the txt file won't load so I may have to find another host I guess

pyro
10-14-2003, 05:46 PM
Yeah, Geocities probably is not the best bet, when it get's to things more complex than... well, anything... :D

Dark Dragon
10-14-2003, 05:59 PM
Well..I'd go back to Tripod but they have everything so hosed up it isn't funny so I am gonna have to look for another free host site that offers both FTP and web based uploads....

I just happen to like web based uploads..sometimes it is more reliable for me..anyways I guess I have to search for one that actually is good...

The Cheat
10-16-2003, 01:16 AM
check out http://www.spaceports.com , they're one of the better free hosts out there.

Sign up with Spaceports to get:

unlimited space
up to 5 GB of transfer for your site per month
your own cgi-bin
PHP scripting
MySQL database support
helpful user forums and real-time support chat rooms

Dark Dragon
10-16-2003, 10:16 AM
Okay..thanks..I will check it out then. :)

spufi
10-30-2003, 10:29 AM
Originally posted by The Cheat
check out http://www.spaceports.com

I went to their forum and the unlimited space thing isn't true. You get 20MB for a free account, and you can upgrade from there, but you will never actually get unlimited space.

The Cheat
11-04-2003, 01:53 AM
Yeah i guess its not Truely unlimited... When you use up your 20mb space, you hit the button in your control pannel that says "apply for additional space" and you get more though...