Browse Source

added index-file with json-output

kgv14.house 7 years ago
parent
commit
f80d12efda
1 changed files with 25 additions and 0 deletions
  1. 25 0
      index.php

+ 25 - 0
index.php

@@ -0,0 +1,25 @@
+<?php
+
+/**
+* Validates given string as an IP address, returns string on success or false on failure.
+*
+* @param string $String
+* @return mixed
+*/
+function Val_ip ($String) {
+    // Check that given string is a valid IP number.
+    if (long2ip (ip2long ($String)) != $String) {
+        // Wasn't, return error.
+        return false;
+    }
+    // Everything was OK, return string.
+    return $String;
+}
+
+// Create response
+$response = array(
+    "remote_addr" => Val_ip($_SERVER["REMOTE_ADDR"])
+);
+
+echo json_encode($response);
+?>