created api for getting all posts
This commit is contained in:
parent
37110c0f2f
commit
d81d4e4ca4
35
res/forum/api/get_posts.php
Normal file
35
res/forum/api/get_posts.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
include("../../global.php");
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
if (!isset($_SESSION["username"])) goto fail;
|
||||||
|
|
||||||
|
$out = $database -> query("SELECT username FROM user WHERE BINARY username=\"" . $_SESSION["username"] . "\"");
|
||||||
|
|
||||||
|
if ($out -> num_rows != 1)
|
||||||
|
{
|
||||||
|
fail:
|
||||||
|
echo "nope";
|
||||||
|
header("Location: ../../../index.php");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$out = $database -> query("SELECT title, description, photo_id FROM post");
|
||||||
|
|
||||||
|
$output = array();
|
||||||
|
|
||||||
|
while (($res = $out -> fetch_assoc()))
|
||||||
|
{
|
||||||
|
$buffer_array = array();
|
||||||
|
|
||||||
|
foreach ($res as $key => $value)
|
||||||
|
{
|
||||||
|
$buffer_array[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
array_push($output, $buffer_array);
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Content-type: application/json');
|
||||||
|
echo json_encode($output);
|
Loading…
x
Reference in New Issue
Block a user