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
<?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);
}
?>