-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_user_activity.php
More file actions
35 lines (27 loc) · 866 Bytes
/
Copy pathupdate_user_activity.php
File metadata and controls
35 lines (27 loc) · 866 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
32
33
34
35
<?php
require_once 'db.php';
header('Content-Type: application/json');
$response = array();
try {
if (!isset($_POST['user_id'])) {
throw new Exception('User ID is required');
}
$userId = $_POST['user_id'];
$currentTimestamp = date('Y-m-d H:i:s');
// Update the user's last active timestamp
$stmt = $conn->prepare("UPDATE user_accounts SET last_active = :timestamp WHERE id = :userId");
$stmt->execute([
':timestamp' => $currentTimestamp,
':userId' => $userId
]);
if ($stmt->rowCount() > 0) {
$response['status'] = 'success';
$response['message'] = 'Activity updated successfully';
} else {
throw new Exception('User not found');
}
} catch (Exception $e) {
$response['status'] = 'error';
$response['message'] = $e->getMessage();
}
echo json_encode($response);