[GET] GEO Targetting script, Don't Waste Any Traffic!

phpfail

Regular Member
Joined
Aug 21, 2011
Messages
236
Reaction score
107
This is the PHP code needed to geo-target your traffic. It must be installed onto a web page with a .php extension:

Code:
[LEFT][COLOR=#007700][FONT=monospace]function [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]visitorCountry[/FONT][/COLOR][COLOR=#007700][FONT=monospace](){
    [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$ip [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]getenv[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'REMOTE_ADDR'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
    [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$d [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]file_get_contents[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"http://www.ipinfodb.com/ip_query_country.php?ip=[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$ip[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]&output=xml"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
 
    [/FONT][/COLOR][COLOR=#FF8000][FONT=monospace]//Use backup server if cannot make a connection
    [/FONT][/COLOR][COLOR=#007700][FONT=monospace]if (![/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$d[/FONT][/COLOR][COLOR=#007700][FONT=monospace]){
        [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$backup [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]file_get_contents[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"http://backup.ipinfodb.com/ip_query.php?ip=[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$ip[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]&output=xml"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
        [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$answer [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= new [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]SimpleXMLElement[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$backup[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
        if (![/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$backup[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) return [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]false[/FONT][/COLOR][COLOR=#007700][FONT=monospace]; [/FONT][/COLOR][COLOR=#FF8000][FONT=monospace]// Failed to open connection
    [/FONT][/COLOR][COLOR=#007700][FONT=monospace]}else{
        [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$answer [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= new [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]SimpleXMLElement[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$d[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
    }
 
    return [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$answer[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]CountryCode[/FONT][/COLOR][COLOR=#007700][FONT=monospace];
}  [/FONT][/COLOR][/LEFT]

You can then call to the visitor with:
Code:
[LEFT][COLOR=#0000BB][FONT=monospace]$geolocation [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]visitorCountry[/FONT][/COLOR][COLOR=#007700][FONT=monospace]();

if ([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$geolocation[/FONT][/COLOR][COLOR=#007700][FONT=monospace]==[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"US"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]){[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]header[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"location:http://www.UStrafficpage.com/"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);exit;}
if ([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$geolocation[/FONT][/COLOR][COLOR=#007700][FONT=monospace]==[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"GB"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]){[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]header[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"location:http://www.GBtrafficpage.com/"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);exit;}[/FONT][/COLOR][/LEFT]
 
NOTE: Since this is not actually a download, I have
moved this thread to the PHP & Perl section.

"Wiz"
 
This actually makes your websites load longer as your server has to fetch the given address for every visitor.
It would be better to check the ip directly against an ip range list. (just sayin')

kind regards,
SICK
 
Something in this script isn't right. Maybe it's that I don't know where to put my API ID in it, I dunno, but it won't redirect.
 
Yeah but the ipinfodb has a damn whois database available somewhere in there


seems to suggest that is so, where it says enable_hostname.

I've managed to figure out the reason it wasn't working for me was because it's gone to a v3 folder now like this:

http://api.ipinfodb.com//v3/ip-country/?key=my64charkey&ip=$myip&output=xml

Now it queries, but I'm getting some sort of xml error at the end, like this:

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Start tag expected, '<' on line 12

I'm going to be experimenting with trial and error later tonight with ipinfodb adding enable_hostname here and there inside the POST hoping it gets passed on and I get some result somewhere in the XML that includes a whois lookup. If anyone has any suggestions or orientations I'd very much appreciate it, thanks.

Does maxmind have a whois database I could download, save me the bandwidth on every call?
 
Back
Top