Last active
March 4, 2016 14:15
-
-
Save paulusm/9365520 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Read in the existing comments | |
$contents = utf8_encode(file_get_contents("comments.json")); | |
// Convert from JSON format to an Array | |
$commentrecords = json_decode($contents, true); | |
//Add a new array item for the newly posted comment | |
$commentrecords[] = array("name" => strip_tags($_POST["name"]), "comment" => strip_tags($_POST["comment"])); | |
//Save everything back to the file | |
file_put_contents("comments.json", json_encode($commentrecords, JSON_PRETTY_PRINT), LOCK_EX); | |
//Redirect back to the form | |
header("Location: project.php"); | |
die(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment