38 lines
791 B
PHP
38 lines
791 B
PHP
<?php
|
|
|
|
# Define Inital Variables
|
|
$fname = htmlspecialchars($_POST["fname"]);
|
|
$fmsg = htmlspecialchars($_POST["fmessage"]);
|
|
$savemsg = array("name" => $fname, "message" => $fmsg);
|
|
|
|
|
|
|
|
|
|
# Setup JSON
|
|
$data = json_decode(file_get_contents('test.json'), true);
|
|
|
|
|
|
# Add
|
|
array_unshift($data , $savemsg);
|
|
$newURL = "http://192.168.1.180:9890/guestbook/index.html";
|
|
# Check name and message
|
|
if ($fname == "") {
|
|
|
|
header('Refresh:2; url=' . $newURL );
|
|
echo "There is no name, Try again with a name";
|
|
exit();
|
|
}
|
|
if ($fmsg == "") {
|
|
header('Refresh:2; url=' . $newURL );
|
|
echo "There is no message, Try again with a message";
|
|
exit();
|
|
}
|
|
|
|
|
|
|
|
file_put_contents('test.json', json_encode($data, JSON_PRETTY_PRINT));
|
|
|
|
header('Refresh:2; url=' . $newURL );
|
|
echo "Your submisson has been added";
|
|
exit();
|