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, author FROM post ORDER BY id DESC"); $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);