-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstarted_check.php
More file actions
42 lines (32 loc) · 1.28 KB
/
started_check.php
File metadata and controls
42 lines (32 loc) · 1.28 KB
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
36
37
38
39
40
41
42
<?php
header('Content-Type: application/json');
$config = require 'config.php';
$jsonFilePath = $config['paths']['json_file'];
// Check if the request is a POST request
if ($_SERVER['REQUEST_METHOD'] === 'POST' ) {
// Open the q.json file for reading
$file = fopen($jsonFilePath, 'r');
if ($file) {
// Read the current data from the JSON file
$data = json_decode(fread($file, filesize($jsonFilePath)), true);
// Check if competition has already started
if ($data['started']) {
fclose($file);
echo json_encode([
'status' => 'success',
'message' => 'Competition started.',
'started' => $data['started'],
'data' => $data,
'remaining' => max(0, $data['start_time'] - (int) (microtime(true) * 1000)) // Remaining time in ms
]);
} else {
fclose($file);
echo json_encode(['status' => 'success', 'message' => 'Competition has not started.','started'=>$data['started']]);
}
} else {
echo json_encode(['status' => 'error', 'message' => 'Could not open the file.']);
}
} else {
echo json_encode(['status' => 'error', 'message' => 'Invalid request method.']);
}
?>