Scripts
Gastenboek class
Meestal als men een Gastenboek maakt zonder MYSQL, zie je vaak dat ze niet gesorteerd zijn. Verder maakt dit script geen gebruik van een controle mechanisme voor scheldwoorden. Dit is ook pas versie 0.1 van het script. Dus alle uitbreidingen zijn welkom.
gastenboek-class
|| class.guestbook.php ||
<?
/*********************************************************
* Software: Guestbook *
* Version: 0.1 *
* Date: 2005-07-26 *
* Author: Jeroen Vercoulen *
* License: Freeware *
* PHP: 4.3.4 *
* *
* You may use and modify this software as you wish. *
**********************************************************/
class guestbook
{
var $fd;
var $content;
var $post;
function open_guestbook($filename , $type)
{
$this->fd = fopen($filename , $type , 1);
}
function fill_array()
{
if ($this->fd)
{
while (!feof($this->fd))
{
$this->content[] = fgets($this->fd, 4096);
}
}
}
function sort_content()
{
rsort($this->content);
}
function view_guestbook()
{
$h="<table>";
for ( $i = 0 ; $i < sizeof($this->content) ; $i++ )
{
$message = explode (" || " , $this->content[$i]);
$h.="<tr><td>";
$h.="<table>";
$h.="<tr><td>";
$h.="On ".date("d-m-Y H:i:s", $message[0])." <a href='mailto:".$message[2]."'>".$message[1]."</a> posted:";
$h.="</td></tr>";
$h.= "<tr><td>";
$h.=$message[4];
$h.="</td></tr>";
$h.="</table>";
$h.="</td></tr>";
}
$h.="</table>";
return $h;
}
function check_message($message)
{
if (stristr($message," || "))
{
return false;
}
else
{
return true;
}
}
function post_message($name, $email, $message)
{
$date = mktime();
$ip = $_SERVER['REMOTE_ADDR'];
$this->post = "\n".$date ." || ". $name ." || ". $email ." || ". $ip ." || ". $message."";
$fwritten = fwrite($this->fd, $this->post);
}
function close_guestbook()
{
fclose($this->fd);
}
}
?>
|| index.php ||
<?
include('./class.guestbook.php');
$guestbook= new guestbook;
$guestbook->open_guestbook("guestbook.txt" , "r+");
$guestbook->fill_array();
$guestbook->sort_content();
if (isset($post_messages))
{
if ((isset($message)) && ($guestbook->check_message($message)))
{
$guestbook->post_message($name, $email, $message);
header("location: destination_url.php");
}
else
{
$h.="<form name=post action=".$_SERVER['PHP_SELF']." method=post>";
$h.="<table>";
if ((isset($message)) && (!$guestbook->check_message($message)))
{
$h.="<tr><td>";
$h.="Er is een ongeldige bericht ingevoerd!!!";
$h.="</tr></td>";
}
$h.="<tr><td>";
$h.="</tr></td>";
$h.="Naam";
$h.="<tr><td>";
$h.="<input type=text name=name value=".$name.">";
$h.="</tr></td>";
$h.="<tr><td>";
$h.="E-mail";
$h.="</tr></td>";
$h.="<tr><td>";
$h.="<input type=text name=email value=".$email.">";
$h.="</tr></td>";
$h.="<tr><td>";
$h.="Bericht";
$h.="</tr></td>";
$h.="<tr><td>";
$h.="<textarea name=message cols=40 rows=10>".$message."</textarea>";
$h.="</tr></td>";
$h.="<tr><td>";
$h.="<input type=submit name=post_messages value=post>";
$h.="</tr></td>";
$h.="</table>";
$h.="</form>";
}
}
else
{
$h.="<form name=post action=".$_SERVER['PHP_SELF']." method=post>";
$h.="<table>";
$h.="<tr><td>";
$h.="<input type=submit name=post_messages value=post>";
$h.="</tr></td>";
$h.="</table>";
$h.="</form>";
$h.=$guestbook->view_guestbook();
}
$guestbook->close_guestbook();
echo $h;
?>
Reacties
0