Click to See Complete Forum and Search --> : Making a message board.
invision
11-26-2003, 06:51 AM
My hands are up, Ive only began learning PHP two weeks ago. Im in dire need of getting help to make a message board, like a guestbook where people can post threads etc. without having to register, any clues?
Thanks in advane,
Mike.
Sexay_Hamster
11-26-2003, 09:06 AM
why not just download one?
because making a discussion forum system is one of the toughest things to do and is very time consuming...
and you will need a lot more than two weeks experience to make one...
Here's a very simple guestbook that I made that might help you get started. You can try it at http://www.infinitypages.com/temp/guestbook.php.
<?PHP
$filename = "guestbook.txt";
$text = "";
if (isset($_POST["submit"])) {
$name = htmlspecialchars(stripslashes($_POST["name"])); #remove HTML and slashes
$message = htmlspecialchars(stripslashes($_POST["message"])); #remove HTML and slashes
#check to make sure they have entered text in both fields
if (!empty($name) && !empty($message)) {
#split words that are more than 50 characters long
$message = explode(" ", $message);
$splitmessage = "";
foreach ($message as $word) {
$splitmessage .= wordwrap($word, 50, " ", 1)." ";
}
$message = $splitmessage;
#set the date and time
$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");
flock ($fp, LOCK_EX);
fwrite ($fp, $value);
flock ($fp, LOCK_UN);
fclose ($fp);
}
else {
$error = "Please enter your name and a message.";
}
}
?>
<!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>
<?PHP
if (isset($error)) {
echo "<p style=\"color: #f00; background: transparent;\">$error</p>";
}
?>
<form action="<?PHP echo $_SERVER["PHP_SELF"]; ?>" method="post">
<p>Your Message:<br>
<textarea name="message" rows="7" cols="50"><?PHP if (isset($message)) { echo $message; } ?></textarea><br>
Your Name: <input type="text" name="name" <?PHP if (isset($name)) { echo "value=\"$name\""; } ?>>
<input type="submit" name="submit" value="submit"></p>
</form>
<?PHP
$contents = @file($filename) or die("No files in guestbook.");
foreach ($contents as $line) {
$text .= $line;
}
$text = split("<break>", $text);
$text = array_reverse($text); # removing this line will put newest comments at the bottom
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>
invision
11-27-2003, 03:13 AM
thanks so much Pyro. Im in your debt.
You are very welcome... :)