Skip to content

Commit

Permalink
add initial version of the php server
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyMathys committed Feb 5, 2015
1 parent 558e0c7 commit d62a968
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
$comments = file_get_contents('_comments.json');
switch($_SERVER["REQUEST_URI"]) {
case '/':
echo file_get_contents('./public/index.html');
break;
case '/comments.json':
if($_SERVER['REQUEST_METHOD'] === 'POST') {
$commentsDecoded = json_decode($comments, true);
$commentsDecoded[] = ['author' => $_POST['author'],
'text' => $_POST['text']];

$comments = json_encode($commentsDecoded);
file_put_contents('_comments.json', $comments);
}
header('Content-Type: application/json');
echo $comments;
break;
default:
return false;
}

0 comments on commit d62a968

Please sign in to comment.