rautafarmi/api.php

38 lines
1.0 KiB
PHP
Raw Normal View History

2022-09-11 16:01:14 +00:00
<?php header('Content-Type: application/json'); ?>
{
"posts": [
<?php
require "creds.php";
function test_input($data) {
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if (isset($_GET["postID"])) {
$postID = test_input($_GET["postID"]);
$result = mysqli_query($mysqli, "SELECT PostID,Username,Time,Message FROM posts WHERE PostID = ".$postID);
} else {
$postID = "";
$result = mysqli_query($mysqli, "SELECT PostID,Username,Time,Message FROM posts ORDER BY PostID DESC");
}
while($res = mysqli_fetch_array($result)) {
echo " {\n";
echo ' "postID": '.$res['PostID'].",\n";
echo ' "username": "'.$res['Username'].'"'.",\n";
echo ' "time": "'.$res['Time'].'"'.",\n";
$message = str_replace("\r\n","\\n",test_input($res['Message']));
//$message = str_replace('"','a',$amessage]);
echo ' "message": "'.$message.'"'."\n";
if($res['PostID'] == "1" || $res['PostID'] == $postID) {
echo " }\n";
} else {
echo " },\n";
}
}
?>
]
}