WebServ/www/public/M6/egyTalk/api/getPostsByUID.php

27 lines
672 B
PHP
Raw Normal View History

2024-09-27 09:10:29 +00:00
<?php
session_start();
$uid = $_GET['uid'];
$response['auth'] = false;
$response['posts'] = null;
if (isset($_SESSION['uid'])) {
$response['auth'] = true;
include('../model/dbEgyTalk.php');
$db = new dbEgyTalk();
$response['posts'] = $db->getUserPosts($uid);
for($i = 0; $i < sizeof($response['posts']); $i++) {
$comments = $db->getComments($response['posts'][$i]['pid']);
$response['posts'][$i]['comments'] = $comments;
}
}
// Behövs för session-cookies och anger att formatet är json
header('Access-Control-Allow-Credentials: true');
header('Content-Type: application/json');
echo json_encode($response, JSON_UNESCAPED_UNICODE);