A typical wet coast rainy Sunday morning and up early waiting for Canada to take gold in Olympic hockey later today. With sometime on my hands, onto the net I go. Now if you use B2Evolution's blog, you most likely have LiveHits plugin installed. Recently i noticed my Google Maps API was putting all the markers to the left of International Date line and stacking them vertically, what the deuce???.....hmmmm...now that's odd. Now i guess i am being a bit of a stat junkie curious where my readers are coming from and this plugin is a nice graphic way of showing me where, in near real time, my visitors are coming from on this great planet. And now it is broken and been that way for a couple weeks now. With some spare idle time on my hands while i wait for the liquid wake up juice, aka coffee, to kick in, i decided to look into the issue.
So whenever you have an issue with software, troubleshooting 101 says it is always best to start out with the creator's site to see if it is a known issue and has been reported or if a possible fix, patch and/or update is available. So off to the LiveHits site but alas, no recent updates to the plugin and only 1 comment about the issue but no solution. At the time of this post, there are 4 comments awaiting moderation, what those are and if they have the fix?, no clue. Well, i guess i'm going to have to fix it if i want to continue using it.
So after some reading on Google Maps API's and how they work, i did some tests to validate functionality. Next step was to see how the code passed the Latitude and Longitude to Google. It uses the following URL: http://api.hostip.info/get_html.php?position=true&ip=000.000.000.000 where 000.000.000.000 is the IP of your visitor to get city, country, longitude and latitude. Taking my own IP and submitting it to the URL; voila! City, Country, longitude and latitude returned, excellent. Now that i know what is returned and in what order, now it's time to pop the hood and see what the LiveHits PHP code is doing.
After a couple quick scans of the code, i came across this in _livehits.plugin.php file:
// Look up the location of the IP
if (!empty($row->hit_remote_addr)) {
$url = "http://api.hostip.info/get_html.php?position=true&ip=$row->hit_remote_addr";
$rawlocation = $this->fetch_remote_page( $url );
if (!empty($rawlocation)) {
$loc_array = explode(':', $rawlocation);
$location = $loc_array[1];
$country = trim(str_replace('City', '', $loc_array[1]));
$city = trim(str_replace('Latitude', '', $loc_array[2]));
$lat = trim(str_replace('Longitude', '', $loc_array[3]));
$lon = trim($loc_array[4]);
}
}
Hmmm...an array with explode and a string replace. Now I know the api.hostip.info returns the lookup in this order:
Country: CANADA (CA)
City: Wet Coast (Unknown city)
Latitude:
Longitude:
IP:
On February 24, he 



Recent comments