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

Need Someone To Code For Me PHP Geo-Targetting

Discussion in 'PHP & Perl' started by gimme4free, Dec 17, 2008.

  1. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,879
    Likes Received:
    1,932
    I am looking for someone to create me a PHP/Javscript script, it doesn't matter if it has been coded from someone elses script. Preferably code it from this script:
    http://www.geobytes.com/GeoDirection.htm
    HTML:
    <head>
        <script language="Javascript" src="http://gd.geobytes.com/Gd?after=-1"></script>
        <script language="javascript">
        var sSpanishLocations="ES,MX,GT,SV,HN,NI,CR,EC,PE,CU,DO,PR,PA,VE,CO,BO,AR,CL,PY,UY";
        var sGermanLocations="DE,AT,CH";
        var sFrenchLocations="FR,BE";
        var sPhilippineLocations="PH";
        var sKoreanLocations="KP,KR";
        var sChineseLocations="CN";
        if(typeof(sGeobytesLocationCode)!="undefined")
        {
           var sCountryCode=sGeobytesLocationCode.substring(0,2);
           if(sCountryCode!="US"&&sCountryCode!="CA")
           {
              if(sSpanishLocations.indexOf(sCountryCode)>=0)
              {
                 // Spanish Visitors would go here
                 document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=Spanish.htm'>");
              }else if(sGermanLocations.indexOf(sCountryCode)>=0)
              {
                 // German Visitors would go here
                 document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=German.htm'>");
              }else if(sFrenchLocations.indexOf(sCountryCode)>=0)
              {
                 // French Visitors would go here
                 document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=French.htm'>");
              }else if(sPhilippineLocations.indexOf(sCountryCode)>=0)
              {
                 // Philippine Visitors would go here
                 document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=Philippine.htm'>");
              }else if(sKoreanLocations.indexOf(sCountryCode)>=0)
              {
                 // Korean Visitors would go here
                 document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=Korean.htm'>");
              }else if(sChineseLocations.indexOf(sCountryCode)>=0)
              {
                 // Chinese Visitors would go here
                 document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=Chinese.htm'>");
              }else
              {
                 // World Visitors would go here
                 document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=World.htm'>");
              }
           }
        }
        </script>
        </head>
    It must not use MySQL. If anyone could just change the countries used with this script that is all I am looking for.

    Needs to redirect for:
    US
    UK
    CAN
    AUS
    OTHER

    Just needs to redirect to /aus /uk /us /can /other

    If anyone can do this would be willing to pay, please PM me with price
     
  2. cyklotrial

    cyklotrial Regular Member

    Joined:
    Oct 13, 2008
    Messages:
    248
    Likes Received:
    82
    Location:
    Wonderland
    i can do this for free :)
    Just send me on PM what server do you have
     
    • Thanks Thanks x 2
  3. fatboy

    fatboy Elite Member

    Joined:
    Aug 13, 2008
    Messages:
    1,618
    Likes Received:
    3,227
    Occupation:
    Retired
    Location:
    Old Peoples Home
    Done this before and posted code here for it - can't find it at the mo!
    Feel free to PM if you need a hand
     
  4. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,879
    Likes Received:
    1,932
    Got it sorted now, cyklotrial coded the lot for me for free. Thanks a lot :D
     
  5. lozzzer

    lozzzer Regular Member

    Joined:
    Nov 14, 2008
    Messages:
    211
    Likes Received:
    37
    Location:
    BHW
    i wud suggest you use maxmind db ...its free and lot more accurate than anything else
     
    Last edited: Dec 17, 2008
  6. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,879
    Likes Received:
    1,932
    Im looking for my users to download the script and upload, far more ease of use with a CURL script. No MySQL / phpMyAdmin / support questions :D
     
  7. cyklotrial

    cyklotrial Regular Member

    Joined:
    Oct 13, 2008
    Messages:
    248
    Likes Received:
    82
    Location:
    Wonderland
    PHP:
    <?php 



    // Get country code corresponding to an IP address 







    function get_country_code ($ip) {



    $c curl_init();



    curl_setopt($cCURLOPT_URL"http://www.topwebhosts.org/whois/index.php?query=$ip");//otwieramy Å‚acze ze strona



    curl_setopt($cCURLOPT_HEADER1);



    curl_setopt($cCURLOPT_VERBOSE1);



    curl_setopt($cCURLOPT_RETURNTRANSFER,1);



    curl_setopt($cCURLOPT_USERAGENT'Mozilla/5.0 (X11; U; Linux i686;pl; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3');



    curl_setopt($cCURLOPT_ENCODING'gzip');



    curl_setopt($cCURLOPT_ENCODING'deflate');



    curl_setopt($cCURLOPT_ENCODING'');



    curl_setopt($cCURLOPT_FOLLOWLOCATION1);



    $page curl_exec($c);



    $code explode('country',$page);



    $code explode(':',$code[1]);



    $code explode('admin-c:',$code[1]);



    $country_code=trim($code[0],"admin-c:");



    return 
    $country_code;



    }



    // Detect user's IP address



    $user_ip $_SERVER["REMOTE_ADDR"];







    // COUNTRY CODE, eg. us, fr, vn



    $country_code get_country_code($user_ip);







    switch(
    $country_code)



        {



            case 
    'US':



                
    //redirect to US page            



                
    break;



            case 
    'UK':



                
    //redirect to FR page            



                
    break;



            case 
    'CAN':



                
    //redirect to CAN page            



                
    break;



            case 
    'AUS':



                
    //redirect to AUS page            



                
    break;



    //etc...etc...etc here you can ad more countries 



            
    default://other coutries



                //default redirect



        
    }











    ?>

    cheers
     
    • Thanks Thanks x 4
  8. ultimatium1

    ultimatium1 Junior Member

    Joined:
    Oct 10, 2008
    Messages:
    107
    Likes Received:
    19
    btw gimme4free/Other users who use the above script, The problem you may have with cyklotrial script is, That script is pulling the Ip from topwebhosts database, which will may have a limit to how many ips it can pull per user per day.
    Thats why its best to run off your own database, This way ur using your own resources
     
  9. zone69

    zone69 Junior Member

    Joined:
    Nov 24, 2008
    Messages:
    196
    Likes Received:
    1,290
    I think max-mind has the best solution to do geo-targetting. It's quite easy to use and by using the geo-lite db it's free. You can do it all without MySQL and can update the geo-country db monthly, on the 1st of each month. Also since all calls are local once setup there are no http calls to external sites that may fail.

    Based on the geo-targetting gimme4free requested here is how you would do it:

    First download the binary db.
    Code:
    http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
    
    Next download the API
    Code:
    http://geolite.maxmind.com/download/geoip/api/php/geoip.inc
    
    Place both of these on your webserver and unzip GeoIP.dat.gz. Make sure the file that is created is called GeoIP.dat and if not rename it as such OR change the script to address the correct .dat file below.

    Now here's the script that will use these to redirect based on the source location of the hit. Make sure this script resides in the same directory as the .inc and .dat file above.

    PHP:
    <?php

    include("geoip.inc");
    $ip=$_SERVER['REMOTE_ADDR'];
    $gi geoip_open("GeoIP.dat",GEOIP_STANDARD);

    $country_code geoip_country_code_by_addr($gi"$ip");

    // Country name is not used so commented
    // Get Country Name based on source IP
    //$country = geoip_country_name_by_addr($gi, "$ip");

    geoip_close($gi);

    switch(
    $country_code)

        {
            case 
    "US"header("Location: http://Your_American_page"); break;
            case 
    "CA"header("Location: http://Your_Canadian_Page"); break;
            case 
    "UK"header("Location: http://Your_U.K._Page"); break;
            case 
    "AU"header("Location: http://Your_Australian_Page"); break;
            default: 
    header("Location: http://Where_the_rest_of_the_visitors_go");
    }
    ?>
    Hope this helps somebody here!
     
    • Thanks Thanks x 34
  10. cam94z28

    cam94z28 Newbie

    Joined:
    Nov 22, 2008
    Messages:
    13
    Likes Received:
    1
    You are awesome zone69. Everything else that's been this good has been paid. Tested from a china web proxy and it did what it was supposed to do. Thanks again.

    If anyone wants to send all Non-US somewhere else, then delete the 3 lines in between "default:" and case "US"
     
    • Thanks Thanks x 1
  11. zone69

    zone69 Junior Member

    Joined:
    Nov 24, 2008
    Messages:
    196
    Likes Received:
    1,290
    I'm glad this worked for you! You are right you can add or takeaway countries as you see fit. The script will test each condition and fall back to default if a country is not found in your case statement. So as you stated, if you keep just US and default then it will serve US to one URL that you defined and the rest of the traffic will fall back to the default.

    P.S. Don't forget to update your .dat file each month to keep your IP to Country db up to date. It is updated on the 1st of each month.

    Happy New Year!
     
  12. kaloss

    kaloss Registered Member

    Joined:
    Aug 12, 2008
    Messages:
    64
    Likes Received:
    7
    zone69
    perfect, i was just looking for this.
    do you think the came could be done with OPENX
    and HOW?

    thanks
     
  13. zone69

    zone69 Junior Member

    Joined:
    Nov 24, 2008
    Messages:
    196
    Likes Received:
    1,290
    I've never used OPENX to serve ads but I'm sure there would be a way to integrate it somehow but unfortunately I do not know how to without actually having it running so I could see the code.
     
  14. jabbidoo

    jabbidoo Junior Member

    Joined:
    Oct 21, 2008
    Messages:
    173
    Likes Received:
    151
    Thanks zone69 for your nice solution. Just set it up and have a few questions. Does the visitor load the data of GeoIP.dat? Because of of this line:
    Code:
    $gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
    If so, it would be very slow, right?
    I tested this with a few proxies, a few of them denied and others didn't load the page although I could load other pages with the proxies. Did I have bad luck or where could be the problem?
    Thanks in advance for any help!!
     
  15. zone69

    zone69 Junior Member

    Joined:
    Nov 24, 2008
    Messages:
    196
    Likes Received:
    1,290
    Actually I use this solution for sites that have quite pretty good traffic and performance is excellent for me.

    One thing to check is to make sure the .dat file was transerred using binary mode if you unzipped it locally on your computer and then transferred it.

    The geoip_open is a function that maxmind provides and basically it opens the .dat file to be read. It is actually very fast. On my sites, with 100K hits a day I still get millisecond responses all the time.

    The only proxies I have used to test are TOR and although the the proxies are very slow I do get the correct results for the country returned.

    If you PM me the url you are testing with I can help you get it working.
     
  16. kammykhan

    kammykhan Regular Member

    Joined:
    Dec 23, 2008
    Messages:
    208
    Likes Received:
    96
    Occupation:
    Grafter!!
    Location:
    At Home!
    how could i use this script to geo target my links AND blank referer?
     
  17. 00CivicEX

    00CivicEX Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 3, 2009
    Messages:
    293
    Likes Received:
    214
    Just setup multiple home pages, all identical except the links in the are for diffrent traffic. So say a guy from UK come to your page the page redirects him to www.yoururl.com/UK

    PHP:
    <?php
     
    include("geoip.inc");
    $ip=$_SERVER['REMOTE_ADDR'];
    $gi geoip_open("GeoIP.dat",GEOIP_STANDARD);
     
    $country_code geoip_country_code_by_addr($gi"$ip");
     
    // Country name is not used so commented
    // Get Country Name based on source IP
    //$country = geoip_country_name_by_addr($gi, "$ip");
     
    geoip_close($gi);
     
    switch(
    $country_code)
     
        {
            case 
    "US"header("Location: http://yoururl.com/us"); break;
            case 
    "CA"header("Location: http://yoururl.com/ca"); break;
            case 
    "UK"header("Location: http://yoururl.com/uk"); break;
            case 
    "AU"header("Location: http://yoururl.com/au"); break;
            default: 
    header("Location: http://Where_the_rest_of_the_visitors_go");
    }
    ?>
    Then have each link do a meta refresh when clicked....I think this is what u mea anywayz
     
    • Thanks Thanks x 1
  18. TheLoser

    TheLoser Registered Member

    Joined:
    Feb 5, 2009
    Messages:
    72
    Likes Received:
    13
    Is MySQL access faster than opening and reading the flat-file? Also, how effective is the lite version compared to the full version?

    Thanks :)
     
  19. fatboy

    fatboy Elite Member

    Joined:
    Aug 13, 2008
    Messages:
    1,618
    Likes Received:
    3,227
    Occupation:
    Retired
    Location:
    Old Peoples Home
    Geo script -> page 1 -> page 2 -> affiliate page.
    Page 1 - 2 is the double meta refresh thing.

    Think that should do you.
     
  20. senso851

    senso851 BANNED BANNED

    Joined:
    Jan 6, 2009
    Messages:
    133
    Likes Received:
    125
    Thanks for the script bro.Saved me some time