-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreact.php
More file actions
30 lines (26 loc) · 929 Bytes
/
react.php
File metadata and controls
30 lines (26 loc) · 929 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
<?php
require_once __DIR__ . '/includes/functions.php';
$postId = isset($_GET['post_id']) ? (int)$_GET['post_id'] : 0;
$redirect = $_GET['redirect'] ?? 'index.php';
$type = $_GET['type'] ?? 'like';
if ($postId <= 0) {
header('Location: ' . $redirect);
exit;
}
if ($type === 'dislike') {
$cookieName = 'disliked_post_' . $postId;
if (!isset($_COOKIE[$cookieName])) {
$stmt = db()->prepare('UPDATE posts SET dislikes = dislikes + 1 WHERE id = ?');
$stmt->execute([$postId]);
setcookie($cookieName, '1', time() + 86400 * 30, '/');
}
} else {
$cookieName = 'liked_post_' . $postId;
if (!isset($_COOKIE[$cookieName])) {
$stmt = db()->prepare('UPDATE posts SET likes = likes + 1 WHERE id = ?');
$stmt->execute([$postId]);
setcookie($cookieName, '1', time() + 86400 * 30, '/');
}
}
header('Location: ' . $redirect);
exit;