A SIMPLE PHP GUEST BOOK BY NRGPRO
Copy And Paste
¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
<?php
// SIMPLE PHP Guestbook BY NRGPRO
// NRG_0098@Yahoo.com
// http://www.NRG-Pro.com
// Error?
$error = false;
// Sign Guestbook
function signGuestbook(){
// gain access to the global form variables
global $name,$email,$webpage,$comments;
// put a new guestbook entry together
$new_guestbook_entry = urlencode($name).",".urlencode($email).",".urlencode($webpage).",".urlencode($comments)."\n";
// write the new guestbook entry to
// the guestbook data file
$fp=fopen("guestbook.data",a) or exit;
fwrite($fp,$new_guestbook_entry);
fclose($fp);
// reset form variables
$name="";
$email="";
$webpage="";
$comments="";
}
function readGuestbook(){
// Read Data
$fp=fopen("guestbook.data",r) or exit;
$rawdata=fread($fp,filesize("guestbook.data"));
fclose($fp);
// Guestbook is Empty
if($rawdata == ""){
echo "<p><font face=\"sans-serif\">No Entries!</font></p>";
return;
}
// Array Element
$each_line = explode("\n",$rawdata);
// Sort By Newest
rsort($each_line);
// Guestbook is Not Empty
$entries = count($each_line)-1;
echo "<p><font face=\"sans-serif\">Entries :<b>$entries</b> entries</font></p>";
// Step Through Each Guestbook Entry
for ($key = 0; $key < count($each_line)-1; $key++){
$temp = explode(",",$each_line[$key]);
$guestbook[$key]["name"] = $temp[0];
$guestbook[$key]["email"] = $temp[1];
$guestbook[$key]["webpage"] = $temp[2];
$guestbook[$key]["comments"] = $temp[3];
}
// Entries In the Guestbook
for($key = 0; $key < count($guestbook); $key++){
echo "<p><font face=\"sans-serif\"><b>Name:</b> ";
echo htmlspecialchars(urldecode($guestbook[$key]["name"]));
echo "<br><b>Email:</b> ";
echo "<a href=\"mailto:";
echo addslashes(urldecode($guestbook[$key]["email"]));
echo "\">";
echo htmlspecialchars(urldecode($guestbook[$key]["email"]));
echo "</a><br><b>Webpage:</b> ";
echo "<a href=\"";
echo addslashes(urldecode($guestbook[$key]["webpage"]));
echo "\">";
echo htmlspecialchars(urldecode($guestbook[$key]["webpage"]));
echo "</a><br><b>Comments:</b> ";
echo htmlspecialchars(urldecode($guestbook[$key]["comments"]));
echo "</font></p>";
}
}
// Check for Values
if ($sign_guestbook){
if($name != "" && $email != "" && $webpage != "" && $comments != ""){
signGuestbook();
}else{
$error = true;
}
}
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>My PHP Guestbook</title>
</head>
<body>
<p>
<?php if($error){ ?>
<?php } ?>
</p>
<form name=guestbook method="post" action="guestbook.php">
<div align="left">
<table border="0" cellpadding="5" cellspacing="0">
<tr>
<td valign="top" align="left"><font face="sans-serif">Name:</font></td>
<td valign="top" align="left"><input type="text" name="name" size="70" value="<?php echo addslashes($name); ?>"></td>
</tr>
<tr>
<td valign="top" align="left"><font face="sans-serif">Email:</font></td>
<td valign="top" align="left"><input type="text" name="email" size="70" value="<?php echo addslashes($email); ?>"></td>
</tr>
<tr>
<td valign="top" align="left"><font face="sans-serif">Webpage:</font></td>
<td valign="top" align="left"><input type="text" name="webpage" size="70" value="<?php echo addslashes($webpage); ?>"></td>
</tr>
<tr>
<td valign="top" align="left"><font face="sans-serif">Comments:</font></td>
<td valign="top" align="left"><textarea rows="5" name="comments" cols="61" wrap=virtual><?php echo htmlspecialchars($comments); ?></textarea></td>
</tr>
<tr>
<td valign="top" align="left"></td>
<td valign="top" align="left"><input type="hidden" name="sign_guestbook" value="true"><input type="submit" value="Submit"> <input type="reset" value="Reset"></td>
</tr>
</table>
</div>
</form>
<p>
<?php readGuestbook(); ?>
</p>
</body>
</html>
Edited by Donna, 16 September 2005 - 08:08 PM.
