NGPriest's Blog

NGPriest's Blog

Site GeoIP And Site Downtime

Okays, after typing my previous post, i started working on a new project to make the site load faster, by moving all the content off random servers (as there was a 33% chance the files will get loaded from your nearest server.
(aka Malaysia would LAG Australian viewers)
which was never a problem for me, since i rarely read the site (all comments are emailed to me and all posts are normally bypassing the main site and into the admin panel)

So, this is the finished coding

Part 1:

[sourcecode language=”php”]
<?php
require_once "/home/ngpriest/php/Net/GeoIP.php";
$geoip = Net_GeoIP::getInstance("/home/ngpriest/public_html/GeoIP.dat");
$CountryCode = $geoip->lookupCountryCode($_SERVER[‘REMOTE_ADDR’]);
$CountryName = $geoip->lookupCountryName($_SERVER[‘REMOTE_ADDR’]);
?>
[/sourcecode]

This loads 2 variables, $CountryCode and $CountryName

Part 2

[sourcecode language=”php”]
<?php
if ($CountryCode=="AU"){
echo "Script for Australia";
}
elseif ($CountryCode=="MY"){
echo "Script for Malaysia";
}
elseif ($CountryCode=="SG"){
echo "Script for Singapore";
}
else {
$k=rand(1,3);
if ($k=="1"){
echo "Script for Australia";
}
elseif ($k=="2"){
echo "Script for Malaysia";
}
elseif ($k=="3"){
echo "Script for Singapore";
}
}
?>
[/sourcecode]

So yeah, as you can see, we have 3 if, which asks if our $CountryCode is AU, MY or SG and if they aren’t, we’ll go back to the 33% of picking a random server

While implementing the above code, i screwed up the index.php file, which stores the main site, along with all additional main coding?

So, i searched for approx 1-2mins for a backup (and didn’t find any), i decided to write a new one?
And it looks closely like what it was before

But tell me if you find any bugs?

Leave a Reply