berichten balkje op website
Ik heb een script gedownload voor een berichtenbalkje voor een website het script werkt verder prima alleen zou ik graag dat het berichten balkje waarin de geplaatste tekst komt op een afzonderlijke pagina komt.Ik zelf heb er niet zoveel verstand van wil graag dat als je een bericht wilt plaatsen dat je middels een aanklikbare link een bericht kan toevoegen hier is de link hoe het er nu uitziet http://www.regionaleartiesten.nl/messageBar/index.php
zou iemand hiermee kunnen helpen b.v.b. mijn dank
Gr. Jack
en dit is het script
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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
require('config.php');
session_start();
$errors = '';
$success = false;
$postNotSet = false;
if(isset($_POST['add'])) {
if($_SESSION["csrf_token"] != $_POST['csrf_token']) {
$postNotSet = true;
}
if(empty($_POST['user']) || strlen($_POST['user']) < $minNameLength) {
$errors .= 'Name must be longer than '. $minNameLength .' characters<br/>';
}
if(empty($_POST['user']) || strlen($_POST['user']) > $maxNameLength) {
$errors .= 'Name must be shorter than '. $maxNameLength .' characters<br/>';
}
if(empty($_POST['message']) || strlen($_POST['message']) < $minMessageLength) {
$errors .= 'Message must be longer than '. $minMessageLength .' characters<br/>';
}
if(strlen($_POST['message']) > $maxMessageLength) {
$errors .= 'Message must be shorter than '. $maxMessageLength .' characters<br/>';
}
if(empty($errors) && ! $postNotSet) {
if(addMessage($_POST['user'], $_POST['message'], $dbh)) {
$succcess = true;
};
}
}
if(! empty($errors)) {
echo '<span style="color: #c00;">'.$errors.'</span>';
}
if($success) {
echo '<span style="color: green;">successfully added your message to the message bar.</span>';
}
$_SESSION["csrf_token"] = uniqid();
?>
<html>
<head>
<script src="smilies.js" type="text/javascript"></script>
</head>
<body>
<div style="margin: 25px auto; width: 1000px;">
<marquee><?php echo getMessages($dbh); ?></marquee>
<form method="post">
<table>
<tr>
<td>
Naam:
</td>
<td>
<input type="text" name="user" value="<?php (isset($_POST['user']) && ! empty($_POST['user'])) ? $_POST['user'] : ''; ?>" />
</td>
</tr>
<tr>
<td>Bericht</td>
<td>
<input type="text" name="message" value="<?php (isset($_POST['message']) && ! empty($_POST['message'])) ? $_POST['message'] : ''; ?>" />
</td>
</tr>
<tr>
<td>Smilies:</td>
<td width="150">
<?php echo getSmilies($dbh); ?>
</td>
</tr>
<tr>
<td><input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']; ?>" /></td>
<td><input type="submit" name="add" value="Send to message bar" /></td>
</tr>
</table>
</form>
© <a href="https://www.radio-lauwerszee.nl/" target="_blank">Radio-Lauwerszee.nl</a> <?php echo date("Y"); ?>
</div>
</body>
</html>
--------------------------------------
config
<?php
define('CHARSET', 'UTF-8');
$db = 'xxxxxxxxxxxxxx'; // name of the database
$user = 'xxxxxxxxxxx'; // name of the user that belongs to the database
$pass = 'xxxxxxxxx'; // password of the user
$minMessageLength = '10'; // minimal length of the message
$maxMessageLength = '50'; // maximal length of the message
$minNameLength = '2'; // minimal length of the username
$maxNameLength = '50'; // maximal length of the username
$dbh = new PDO('mysql:host=db.regionaleartiesten.nl;dbname='.$db.';charset=utf8', $user, $pass); // pdo connection
/**
* @Description: insert message and username into the database
* @param username: name of the user that inserted the message
* @param message: message of the user
* @param dbh: the database connection object
**/
function addMessage($username, $message, $dbh) {
$stmt = $dbh->prepare("INSERT INTO mb_messages (user, message) VALUES(:user, :message)");
$stmt->execute([':user' => $username, ':message' => $message]);
return true;
}
/**
* @Description: get all messages for the messagebar ordered by id descending
* @param dbh: the database connection object
**/
function getMessages($dbh) {
$messages = 'no messages inserted';
$stmt = $dbh->prepare("SELECT * FROM mb_messages ORDER BY id DESC");
$result = $stmt->execute();
if ($stmt->rowCount() > 0) {
$messages = '';
$first = true;
while($data = $stmt->fetch(PDO::FETCH_ASSOC)){
if(! $first) {
$messages .= ' || ';
}
$messages .= htmlspecialchars($data['user'], ENT_QUOTES, CHARSET) .': '. replaceSmilies($dbh, htmlspecialchars($data['message'], ENT_QUOTES, CHARSET));
$first = false;
}
}
return $messages;
}
/**
* @Description: get all smilies that can be used for the messagebar ordered by name
* @param dbh: the database connection object
**/
function getSmilies($dbh) {
$smilies = '';
$stmt = $dbh->prepare("SELECT * FROM mb_smilies ORDER BY smiley");
$result = $stmt->execute();
if ($stmt->rowCount() > 0) {
while($data = $stmt->fetch(PDO::FETCH_ASSOC)){
$smilies .= '<img src="smilies/'.$data['image'].'" onclick="setSmiley(\''.$data['smiley'].'\')" />';
}
}
return $smilies;
}
/**
* @Description: replace all smilies in the message to images
* @param dbh: the database connection object
* @param message: the message that would be parsed
**/
function replaceSmilies($dbh, $message) {
$smilies = array();
$stmt = $dbh->prepare("SELECT * FROM mb_smilies ORDER BY smiley");
$result = $stmt->execute();
if ($stmt->rowCount() > 0) {
while($data = $stmt->fetch(PDO::FETCH_ASSOC)){
$smilies[$data['smiley']] = '<img src="smilies/'.$data['image'].'" />';
}
}
return str_replace( array_keys($smilies), array_values($smilies), $message);
}
?>
require('config.php');
session_start();
$errors = '';
$success = false;
$postNotSet = false;
if(isset($_POST['add'])) {
if($_SESSION["csrf_token"] != $_POST['csrf_token']) {
$postNotSet = true;
}
if(empty($_POST['user']) || strlen($_POST['user']) < $minNameLength) {
$errors .= 'Name must be longer than '. $minNameLength .' characters<br/>';
}
if(empty($_POST['user']) || strlen($_POST['user']) > $maxNameLength) {
$errors .= 'Name must be shorter than '. $maxNameLength .' characters<br/>';
}
if(empty($_POST['message']) || strlen($_POST['message']) < $minMessageLength) {
$errors .= 'Message must be longer than '. $minMessageLength .' characters<br/>';
}
if(strlen($_POST['message']) > $maxMessageLength) {
$errors .= 'Message must be shorter than '. $maxMessageLength .' characters<br/>';
}
if(empty($errors) && ! $postNotSet) {
if(addMessage($_POST['user'], $_POST['message'], $dbh)) {
$succcess = true;
};
}
}
if(! empty($errors)) {
echo '<span style="color: #c00;">'.$errors.'</span>';
}
if($success) {
echo '<span style="color: green;">successfully added your message to the message bar.</span>';
}
$_SESSION["csrf_token"] = uniqid();
?>
<html>
<head>
<script src="smilies.js" type="text/javascript"></script>
</head>
<body>
<div style="margin: 25px auto; width: 1000px;">
<marquee><?php echo getMessages($dbh); ?></marquee>
<form method="post">
<table>
<tr>
<td>
Naam:
</td>
<td>
<input type="text" name="user" value="<?php (isset($_POST['user']) && ! empty($_POST['user'])) ? $_POST['user'] : ''; ?>" />
</td>
</tr>
<tr>
<td>Bericht</td>
<td>
<input type="text" name="message" value="<?php (isset($_POST['message']) && ! empty($_POST['message'])) ? $_POST['message'] : ''; ?>" />
</td>
</tr>
<tr>
<td>Smilies:</td>
<td width="150">
<?php echo getSmilies($dbh); ?>
</td>
</tr>
<tr>
<td><input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']; ?>" /></td>
<td><input type="submit" name="add" value="Send to message bar" /></td>
</tr>
</table>
</form>
© <a href="https://www.radio-lauwerszee.nl/" target="_blank">Radio-Lauwerszee.nl</a> <?php echo date("Y"); ?>
</div>
</body>
</html>
--------------------------------------
config
<?php
define('CHARSET', 'UTF-8');
$db = 'xxxxxxxxxxxxxx'; // name of the database
$user = 'xxxxxxxxxxx'; // name of the user that belongs to the database
$pass = 'xxxxxxxxx'; // password of the user
$minMessageLength = '10'; // minimal length of the message
$maxMessageLength = '50'; // maximal length of the message
$minNameLength = '2'; // minimal length of the username
$maxNameLength = '50'; // maximal length of the username
$dbh = new PDO('mysql:host=db.regionaleartiesten.nl;dbname='.$db.';charset=utf8', $user, $pass); // pdo connection
/**
* @Description: insert message and username into the database
* @param username: name of the user that inserted the message
* @param message: message of the user
* @param dbh: the database connection object
**/
function addMessage($username, $message, $dbh) {
$stmt = $dbh->prepare("INSERT INTO mb_messages (user, message) VALUES(:user, :message)");
$stmt->execute([':user' => $username, ':message' => $message]);
return true;
}
/**
* @Description: get all messages for the messagebar ordered by id descending
* @param dbh: the database connection object
**/
function getMessages($dbh) {
$messages = 'no messages inserted';
$stmt = $dbh->prepare("SELECT * FROM mb_messages ORDER BY id DESC");
$result = $stmt->execute();
if ($stmt->rowCount() > 0) {
$messages = '';
$first = true;
while($data = $stmt->fetch(PDO::FETCH_ASSOC)){
if(! $first) {
$messages .= ' || ';
}
$messages .= htmlspecialchars($data['user'], ENT_QUOTES, CHARSET) .': '. replaceSmilies($dbh, htmlspecialchars($data['message'], ENT_QUOTES, CHARSET));
$first = false;
}
}
return $messages;
}
/**
* @Description: get all smilies that can be used for the messagebar ordered by name
* @param dbh: the database connection object
**/
function getSmilies($dbh) {
$smilies = '';
$stmt = $dbh->prepare("SELECT * FROM mb_smilies ORDER BY smiley");
$result = $stmt->execute();
if ($stmt->rowCount() > 0) {
while($data = $stmt->fetch(PDO::FETCH_ASSOC)){
$smilies .= '<img src="smilies/'.$data['image'].'" onclick="setSmiley(\''.$data['smiley'].'\')" />';
}
}
return $smilies;
}
/**
* @Description: replace all smilies in the message to images
* @param dbh: the database connection object
* @param message: the message that would be parsed
**/
function replaceSmilies($dbh, $message) {
$smilies = array();
$stmt = $dbh->prepare("SELECT * FROM mb_smilies ORDER BY smiley");
$result = $stmt->execute();
if ($stmt->rowCount() > 0) {
while($data = $stmt->fetch(PDO::FETCH_ASSOC)){
$smilies[$data['smiley']] = '<img src="smilies/'.$data['image'].'" />';
}
}
return str_replace( array_keys($smilies), array_values($smilies), $message);
}
?>
Gewijzigd op 27/12/2019 13:26:40 door Jack vandijk
Dan is het beter leesbaarder.
https://www.ictscripters.com/filebase/Entry/267-PDO-messagebar-berichtenbalk/?s=22db8e9c9ee671f96129c6574b62f9e7c1c4fa41
Toevoeging op 27/12/2019 13:20:38:
Als je alleen het berichtenbalkje wilt tonen, gebruik dit :
Ik noem het bestand 'messages.php'.
Code (php)
Toevoeging op 27/12/2019 13:40:55:
Ik vondi die marqee wat schokkerig.
Met wat speurwerk vond ik deze oplossing.
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
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
<?php
require('config.php');
?>
<html>
<head>
<script src="smilies.js" type="text/javascript"></script>
<!-- https://stackoverflow.com/questions/18417056/marquee-doesnot-scroll-smoothly-need-100-smooth-scroll-for-marquee -->
<style>
.marquee-parent {
position: relative;
width: 100%;
overflow: hidden;
height: 30px;
}
.marquee-child {
display: block;
width: 100%;
/* width of your text div */
height: 30px;
/* height of your text div */
position: absolute;
animation: marquee 20s linear infinite; /* change 5s value to your desired speed */
}
.marquee-child:hover {
animation-play-state: paused;
cursor: pointer;
}
@keyframes marquee {
0% {
left: 100%;
}
100% {
left: -1000px /* same as your text width */
}
}
</style>
</head>
<body>
<div class="marquee-parent">
<div class="marquee-child"><?php echo getMessages($dbh); ?></div>
</div>
</body>
</html>
require('config.php');
?>
<html>
<head>
<script src="smilies.js" type="text/javascript"></script>
<!-- https://stackoverflow.com/questions/18417056/marquee-doesnot-scroll-smoothly-need-100-smooth-scroll-for-marquee -->
<style>
.marquee-parent {
position: relative;
width: 100%;
overflow: hidden;
height: 30px;
}
.marquee-child {
display: block;
width: 100%;
/* width of your text div */
height: 30px;
/* height of your text div */
position: absolute;
animation: marquee 20s linear infinite; /* change 5s value to your desired speed */
}
.marquee-child:hover {
animation-play-state: paused;
cursor: pointer;
}
@keyframes marquee {
0% {
left: 100%;
}
100% {
left: -1000px /* same as your text width */
}
}
</style>
</head>
<body>
<div class="marquee-parent">
<div class="marquee-child"><?php echo getMessages($dbh); ?></div>
</div>
</body>
</html>
Dank je zal er ff mee aan de slag
https://developer.mozilla.org/nl/docs/Web/HTML/Element/marquee
Toevoeging op 27/12/2019 18:21:52:
https://www.w3.org/TR/html50/obsolete.html#the-marquee-element-0