Просмотр исходного кода

You can now use ipinfo.io access token

adolfintel 6 лет назад
Родитель
Сommit
7f17622d5b
3 измененных файлов с 12 добавлено и 3 удалено
  1. 2 0
      doc.md
  2. 7 3
      getIP.php
  3. 3 0
      getIP_ipInfo_apikey.php

+ 2 - 0
doc.md

@@ -41,6 +41,8 @@ Later we'll see how to use the test without PHP, and how to configure the teleme
 
 __Important:__ keep all the files together; all paths are relative to the js file
 
+__Important:__ If you expect to serve more than ~500 tests per day, you will need to sign up to [ipinfo.io](https://ipinfo.io) and edit `getIP_ipInfo_apikey.php` to set your access token.
+
 __Important:__ Make sure PHP is allowed to write to the directory where you're installing the speedtest because getIP.php needs to create a cache file to improve performance.
 
 ## Basic usage

+ 7 - 3
getIP.php

@@ -65,12 +65,16 @@ function distance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo) {
     $dist = sin($latitudeFrom * $rad) * sin($latitudeTo * $rad) + cos($latitudeFrom * $rad) * cos($latitudeTo * $rad) * cos($theta * $rad);
     return acos($dist) / $rad * 60 * 1.853;
 }
-
+function getIpInfoTokenString(){
+	require "getIP_ipInfo_apikey.php";
+	if(empty($IPINFO_APIKEY)) return "";
+	return "?token=".$IPINFO_APIKEY;
+}
 if (isset($_GET["isp"])) {
     $isp = "";
 	$rawIspInfo=null;
     try {
-        $json = file_get_contents("https://ipinfo.io/" . $ip . "/json");
+        $json = file_get_contents("https://ipinfo.io/" . $ip . "/json".getIpInfoTokenString());
         $details = json_decode($json, true);
 		$rawIspInfo=$details;
         if (array_key_exists("org", $details)){
@@ -94,7 +98,7 @@ if (isset($_GET["isp"])) {
 				if(file_exists($locFile)){
 					require $locFile;
 				}else{
-					$json = file_get_contents("https://ipinfo.io/json");
+					$json = file_get_contents("https://ipinfo.io/json".getIpInfoTokenString());
 					$details = json_decode($json, true);
 					if (array_key_exists("loc", $details)){
 						$serverLoc = $details["loc"];

+ 3 - 0
getIP_ipInfo_apikey.php

@@ -0,0 +1,3 @@
+<?php
+$IPINFO_APIKEY=""; //put your token between the quotes if you have one
+?>