-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlike.php
More file actions
31 lines (27 loc) · 811 Bytes
/
like.php
File metadata and controls
31 lines (27 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
require_once('./config/include.php');
require_once('./src/validations.php');
require_once('./src/images.php');
require_once('./src/like_db.php');
require_login('');
header('Content-Type: application/json; charset=utf-8');
if (is_post_request()) {
if (isset($_POST['post_id']) && !empty($_POST['post_id']) && isset($_POST['like']) && !empty($_POST['like'])) {
$post_id = $_POST['post_id'];
$like = $_POST['like'] == "true";
if ($like) {
like($dbc, $post_id, $_SESSION['user_id']);
} else {
dislike($dbc, $post_id, $_SESSION['user_id']);
}
$response = array('postLikeCount' => post_like_count($dbc, $post_id));
echo json_encode($response);
} else {
echo '{"error": "Provide post_id"}';
exit();
}
} else {
header('Location: feed.php');
exit();
}
?>