1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'PHP & Perl' started by phpfail, Jun 16, 2012.

  1. phpfail

    phpfail Regular Member

    Joined:
    Aug 21, 2011
    Messages:
    237
    Likes Received:
    104
    Occupation:
    Webmaster / Internet Marketer
    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]
     
    • Thanks Thanks x 3
  2. WizGizmo

    WizGizmo Super Moderator Staff Member Premium Member

    Joined:
    Mar 28, 2008
    Messages:
    3,833
    Likes Received:
    55,431
    NOTE: Since this is not actually a download, I have
    moved this thread to the PHP & Perl section.

    "Wiz"
     
    • Thanks Thanks x 1
  3. -SICK-

    -SICK- Registered Member

    Joined:
    Jul 17, 2011
    Messages:
    53
    Likes Received:
    22
    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
     
    • Thanks Thanks x 1
  4. paincake

    paincake Power Member

    Joined:
    Aug 18, 2010
    Messages:
    716
    Likes Received:
    3,099
    Home Page:
    Indeed.

    I've used this IP range list in the past:
    http://software77.net/geo-ip/
     
    • Thanks Thanks x 2
  5. onething1

    onething1 Junior Member

    Joined:
    Sep 10, 2010
    Messages:
    116
    Likes Received:
    2
    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.
     
  6. CodingAndStuff

    CodingAndStuff Regular Member

    Joined:
    May 6, 2012
    Messages:
    236
    Likes Received:
    84
    Occupation:
    Swagstronaut
    Location:
    You can't have my bots. Sorry :'(
  7. onething1

    onething1 Junior Member

    Joined:
    Sep 10, 2010
    Messages:
    116
    Likes Received:
    2
    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?