-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.php
58 lines (51 loc) · 1.7 KB
/
init.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
<?php
/**
* Unixtime API
*
* This API provides the current Unix timestamp along with the requesting domain,
* metadata, and developer information.
*
* Developer: Jan Gebser | Brainhub24
* GitHub Repository: https://github.com/Webservice-Digital/Unixtime/
* Company: netcore.digital
*/
// Set the content type to JSON
// https://reqbin.com/req/abghm4zf/json-content-type
header('Content-Type: application/json');
try {
// Get the current Unix timestamp
// https://www.php.net/manual/en/function.time.php
$unixTime = time();
// Get the domain from which the request is being made
// https://www.php.net/manual/en/reserved.variables.server.php
$requestDomain = $_SERVER['HTTP_HOST'];
// GitHub repository URL
$githubRepo = 'https://github.com/Webservice-Digital/Unixtime/';
// Company information
$company = 'netcore.digital';
// Create a structured response array
// https://www.php.net/manual/en/function.array
$response = array(
'success' => true,
'data' => array(
'unixtime' => $unixTime,
'domain' => $requestDomain,
'metadata' => array(
'github_repo' => $githubRepo,
'company' => $company
)
)
);
// Convert the response array to JSON and output it
// https://www.geeksforgeeks.org/php-json-pretty-print
echo json_encode($response, JSON_PRETTY_PRINT);
} catch (Exception $e) {
// Handle errors and provide an informative response
// https://www.php.net/manual/en/language.exceptions.php
$response = array(
'success' => false,
'error' => 'An error occurred.'
);
echo json_encode($response, JSON_PRETTY_PRINT);
}
?>