gastenboek-class
|| class.guestbook.php ||
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?
/*********************************************************
* 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);
}
}
?>
/*********************************************************
* 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 ||
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?
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;
?>
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;
?>