diff --git a/guestbook/guestbook.css b/guestbook/guestbook.css index 5ddefa9..639554e 100644 --- a/guestbook/guestbook.css +++ b/guestbook/guestbook.css @@ -9,3 +9,7 @@ padding-bottom: 20px; padding-top: 10px; } +.date { + padding-top: 0px; + padding-bottom: 15px; +} diff --git a/guestbook/index.html b/guestbook/index.html index 17ab7bd..940b381 100644 --- a/guestbook/index.html +++ b/guestbook/index.html @@ -29,6 +29,9 @@ echo "

"; echo $post["name"] . "
"; echo "

"; + echo '

'; + echo $post["date"] . "
"; + echo "

"; echo "

"; echo $post["message"] . "
"; echo "

"; diff --git a/guestbook/submit.php b/guestbook/submit.php index 069c4a0..5f6ffe4 100644 --- a/guestbook/submit.php +++ b/guestbook/submit.php @@ -1,35 +1,74 @@ $fname, "message" => $fmsg); +class data { + public $name; + public $message; + public $date; + public $mlength; + public $nlength; + function set_date() { + $this->date = date("Y M d"); + } + function set_mlength() { + $this->mlength = strlen($this->message); + } + function set_nlength() { + $this->nlength = strlen($this->name); + } +} +$ndata = new data(); +$name = $ndata->name = htmlspecialchars($_POST["fname"]); +$message = $ndata->message = htmlspecialchars($_POST["fmessage"]); +$ndata->set_date(); +$ndata->set_mlength(); +$ndata->set_nlength(); +$mlength = $ndata->mlength; +$nlength = $ndata->nlength; + # 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 == "") { +# Check name and message +if ($name == "") { header('Refresh:2; url=' . $newURL ); echo "There is no name, Try again with a name"; exit(); } -if ($fmsg == "") { +if ($message == "") { header('Refresh:2; url=' . $newURL ); echo "There is no message, Try again with a message"; exit(); } +if($mlength > 200) { + header('Refresh:2; url=' . $newURL ); + echo "This message is too long"; + exit(); +} +if($nlength > 12) { + header('Refresh:2; url=' . $newURL ); + echo "The name is too long"; + exit(); +} +$data = json_decode(file_get_contents('test.json'), true); + + +foreach($data as $post) { + if ($post["message"] == $message) { + echo "Another message with this text already exists"; + header('Refresh:2; url=' . $newURL ); + exit(); + } +} + + +array_unshift($data , $ndata); file_put_contents('test.json', json_encode($data, JSON_PRETTY_PRINT)); header('Refresh:2; url=' . $newURL );