View Single Post
Slash The Mighty
Member
Join Date: May 2006
Location: Vault 13
Old 12-15-2019 , 00:58   Re: [TF2 Stats] With Web Ranking and Item Logger [v9.1.0]
Reply With Quote #2702

Here's some stuff I've bumped into while updating this myself.
Google's API now costs per call so to keep player.php alive but cheap I've done the following.

The ipinfodb link needed updating as now they are on v3.
Code:
$geourl = "http://api.ipinfodb.com/v3/ip-city/?key=".$geokey."&ip=".$ipAddr."&timezone=false";
$xml = file_get_contents($geourl);
$explodedResult = explode(";", $xml);
$countrycode = $explodedResult[4];
$countryname = $explodedResult[5];
$cityname = $explodedResult[6];
$queryinsertlocation = "INSERT INTO location (STEAMID, IP, COUNTRYCODE, COUNTRYNAME, CITYNAME) VALUES ('".$adr['STEAMID']."', '".$adr['IPAddress']."', '".$countrycode."', '".$countryname."', '".$cityname."')";
mysql_query($queryinsertlocation);
Now the website will again be able to update the location.table in sql.
Below that it looks up the latitude and longitude.
This was previously done via Google but that API costs $5/per 1000,
I'm using opencagedata.com as it's a free alternative.

Code:
$key = $GoogleApi;
$geokey = 'a1************2b3';
$address = urlencode($cityname.", ".$countryname);
$sturl = 'https://api.opencagedata.com/geocode/v1/json?key=' . $geokey . '&q=' . $address;
$res = file_get_contents($sturl);
$stjson = json_decode($res, true);
if(isset($stjson['results'][0]['geometry']['lat'])){$latitude = $stjson['results'][0]['geometry']['lat'];}else{$latitude=5;}
if(isset($stjson['results'][0]['geometry']['lng'])){$longtitude = $stjson['results'][0]['geometry']['lng'];}else{$longtitude=5;}
The satelite picture lookup API I have not found a free alternative for, so I modified my site to just keep utilizing Googles service and pay the $2/per 1000 lookup.
This way however, I'm only paying for 1 service
__________________
---
Slash The Mighty is offline
Send a message via AIM to Slash The Mighty Send a message via MSN to Slash The Mighty Send a message via Skype™ to Slash The Mighty