Created
February 26, 2020 04:59
-
-
Save Mossuru777/b751115fde9f49b32a6f157210cacedf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
switch ($_SERVER["REQUEST_METHOD"]) { | |
case "GET": | |
header("Access-Control-Allow-Origin: *"); | |
header("Content-Type: application/json; charset=utf-8"); | |
header("Cache-Control: no-store"); | |
$remote_addr = $_SERVER["REMOTE_ADDR"]; | |
$remote_host = $_SERVER["REMOTE_HOST"]; | |
if ($remote_host === $remote_addr) { | |
$remote_host = gethostbyaddr($remote_addr); | |
} | |
print(json_encode( | |
[ | |
"ip" => $remote_addr, | |
"hostname" => $remote_host | |
] | |
)); | |
break; | |
case "OPTIONS": | |
header("Access-Control-Allow-Origin: *"); | |
header("Access-Control-Max-Age: 0"); | |
header("Access-Control-Allow-Methods: GET, OPTIONS"); | |
header("Access-Control-Allow-Headers: Content-Type"); | |
http_response_code(204); | |
break; | |
default: | |
http_response_code(405); | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment