guestbook

Gesponsorde koppelingen

PHP script bestanden

  1. guestbook

« Lees de omschrijving en reacties

--------------- ./smilies/smilies.php ---------------

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php

$smiles
= array(    
    ':p'=>'tongue',
    ':?'=>'confused',
    '8)'=>'cool',
    ':|'=>'sleepy',
    ':@'=>'mad',
    ':O'=>'surprised',
    ':d'=>'happy',
    ':)'=>'smile',
    ':D'=>'biggrin',
    ':('=>'cry',
    ':P'=>'drool');

foreach($smiles as $smile=>$image){
    $comment = str_replace($smile,"<img src=./smilies/".$image.".gif>", $comment);
}


?>


--------------- Index.php ---------------
Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head><title>Guestbook</title></head>
<body bgcolor="#98AFC7">
<style type="text/css">
table {
    border: 2px solid #00008B;
    background-color: #e6e6e6;
}

h1 {
    font-family: Tahoma;
}

td {
    border: 1px solid blue;
    font-size: 13px;
    font-family: Tahoma;
}

th {
    border: 1px solid blue;
    font-size: 11px;
    font-family: Tahoma;
}

textarea {
    font-family: Tahoma;
    font-size: 11px;
}

input {
    font-family: Tahoma;
    font-size: 11px;
}

p {
    font-family: Tahoma;
    font-size: 13px;
    text-decoration: underline;
}

font {
    font-family: Tahoma;
    font-size: 12px;
}
</style>
<center>
<h1>Guestbook!</h1>

<?php

$mysqli
=  new mysqli("localhost","root","","guestbook");

$comment = ($_REQUEST["comment"]);
$hashed_comment = md5($comment);

$query = "SELECT count(ID) FROM messages";
$result = $mysqli->query($query);
$queryData = mysqli_fetch_row($result);
$numRows = $queryData[0];

$rowsPerPage = 10;
$pageNum = 1;
$lastPage = ceil($numRows / $rowsPerPage);

if(isset($_GET["page"])) {
    $pageNum = $_GET["page"];
}


$offset = ($pageNum - 1) * $rowsPerPage;

$query = "SELECT * FROM `messages` WHERE `Unique` = '".$hashed_comment."'";
$rs = $mysqli->query($query);

if($rs->num_rows == 0) {
    if(isset($_REQUEST["name"])) {
        $name = trim(strip_tags($_REQUEST["name"]));
    }

    if(isset($_REQUEST["nobot"])) {
        $nobot = trim(strip_tags($_REQUEST["nobot"]));
    }

    if(isset($_REQUEST["comment"])) {
        $comment = nl2br(trim(strip_tags($_REQUEST["comment"])));
            if(empty($name) || empty($comment) || !empty($nobot)) {
                echo "<p>You have to fill in both fields in order to submit a post.</p>";
            }

            else {
                include("./smilies/smilies.php");
                $query = "INSERT INTO messages (`Name`, `Message`, `Unique`, `NoBot`) VALUES('".$mysqli->real_escape_string($name)."','".$mysqli->real_escape_string($comment)."','".$mysqli->real_escape_string($hashed_comment)."','".$mysqli->real_escape_string($nobot)."')";
                $mysqli->query($query);
            }
    }
}

else {
    echo "<p>Don't SPAM!</p>";
}


$query = "SELECT * FROM messages ORDER BY `Date` DESC LIMIT ".$offset.", ".$rowsPerPage."";
$rs = $mysqli->query($query);
while($row = $rs->fetch_array()) {
    echo "<table><tr><td colspan=3>".wordwrap($row["Message"], 38, " ", " ")."</td></tr><tr><th width=200>".$row["Name"]."</th><th width=200>".$row["Date"]."</th><th width=50>#".$row["ID"]."</th></tr></table><br />";
}


$nextPage = $pageNum+1;
$prevPage = $pageNum-1;

if ($pageNum == 1) {
   echo "<font> FIRST PREV </font>";
}

else {
   echo " <a href=\"".$_SERVER['PHP_SELF']."?page=1\"><font>FIRST</font></a> ";
   echo " <a href=\"".$_SERVER['PHP_SELF']."?page=".$prevPage."\"><font>PREV</font></a> ";
}


echo "<font> ( Page ".$pageNum." of ".$lastPage." ) </font>";

if ($pageNum == $lastPage) {
   echo "<font> NEXT LAST </font>";
}

else {
   echo " <a href=\"".$_SERVER['PHP_SELF']."?page=".$nextPage."\"><font>NEXT</font></a> ";
   echo " <a href=\"".$_SERVER['PHP_SELF']."?page=".$lastPage."\"><font>LAST</font></a> ";
}


?>


<p>
<form name='Form1' method='post' action='index.php'>
<table>
    <tr>
        <th width='100'>
            Name:
        </th>
        <td>
            <input name='name' />
        </td>
    </tr>
    <tr>
        <th width='100'>
            Message:
        </th>
        <td>
            <textarea name='comment'></textarea>
            <input type='hidden' name='nobot' />
        </td>
    </tr>
</table>
<br />
<input type='submit' value='Submit' />
</form>
</p>

</center>
</body>
</html>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.