Index.php
Code:
<html>
<head>
<title>Comment Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
<p><font size="+1">Comments Demo:</font></p>
<table width="80%" border="1" cellspacing="0" cellpadding="5">
<tr>
<td align="left">
<?php
if ($file = @file_get_contents("comments.phpdata")) {
echo $file."\n";
}
else {echo "Sorry, but no comments were found.";}
?>
</td>
</tr>
</table>
<p><a href="add.php">Add Comment</a></p>
</div>
</body>
</html>
Add.php
Code:
<html>
<head>
<title>Add Comment Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
<p><font size="+1">Add Comment Demo:</font></p>
<form name="form1" method="post" action="sent.php">
Name: <input name="name" type="text"> -- Email: <input name="email" type="text"><br>
<textarea name="comment" cols="60" rows="10"></textarea><br>
<input type="submit" value="submit"> - <input type="reset" value="reset">
</form>
<a href="index.php">Back</a>
</div>
</body>
</html>
sent.php
Code:
<?php
$filename = "comments.phpdata";
if ($name = stripslashes($_POST['comment'])) {
$comment = str_replace("<","<",$comment); //security
$comment = str_replace(">", ">", $comment); //security
if ($email = stripslashes($_POST['email'])) {
$email = str_replace("<","<",$email); //security
$email = str_replace(">", ">", $email); //security
$email = "<a href=\"mailto:".$email."\">".$email."</a>";
}
else {
$email = "(No Email supplied.)";
}
$name = stripslashes($_POST['name']);
$name = str_replace("<","<",$name); //security
$name = str_replace(">", ">", $name); //security
if (!$name) {
$name = "<i>Anonomous</i>";
}
$hr = "";
if (strlen(@file_get_contents($filename)) > 0) $hr = "\n<hr>";
$add = $hr."Posted by: <b>".$name."</b> -- ".$email."<br>".$comment;
$comments = @file_get_contents($filename).$add;
$file = @fopen($filename, "w+");
@fwrite($file, $comments);
@fclose($file);
$message = "Your comment was successfully added.<br>Redirecting to index.php";
}
else {
$message = "You either entered no data or it was entered incorrectly.<br>Redirecting to index.php";
}
?>
<html>
<head>
<title>Comment Added Demo</title>
<meta http-equiv="refresh" content="3;url=index.php">
</head>
<body>
<div align="center">
<p><font size="+1">Comment Added Demo:</font></p>
<?php echo $message; ?>
</div>
</body>
</html>
the free server I have used is specifically for php.
Bookmarks