-
Notifications
You must be signed in to change notification settings - Fork 0
/
score.php
62 lines (47 loc) · 1.46 KB
/
score.php
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
include './class/store.php';
(new DevCoder\DotEnv('./.env'))->load();
header('X-Frame-Options: DENY');
header('X-XSS-Protection: 1; mode=block');
header('X-Content-Type-Options: nosniff');
header('Strict-Transport-Security: max-age=63072000');
header('Content-type:application/json; charset=utf-8');
header('X-Robots-Tag: noindex, nofollow', true);
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
$match = filter_var($id, FILTER_VALIDATE_REGEXP, [
'options' => ['regexp' => '/^[0-9]+$/']
]);
if ($match === false || $match === null) {
http_response_code(400);
echo json_encode(["error" => "Invalid ID format"]);
exit;
}
$api_url = getenv('APIURL');
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $api_url . $match,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
]);
$response = curl_exec($curl);
if (curl_errno($curl)) {
http_response_code(500);
echo json_encode(["error" => "Failed to fetch data from the API: " . curl_error($curl)]);
curl_close($curl);
exit;
}
curl_close($curl);
if (!$response || !is_valid_json($response)) {
http_response_code(500);
echo json_encode(["error" => "Invalid response from the API"]);
exit;
}
echo $response;
function is_valid_json(string $string): bool {
return json_decode($string) !== null;
}
?>