Need Someone To Code For Me PHP Geo-Targetting

Status
Not open for further replies.

gimme4free

Elite Member
Oct 22, 2008
1,932
1,986
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
 
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
 
i wud suggest you use maxmind db ...its free and lot more accurate than anything else
 
Last edited:
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
 
PHP:
<?php 



// Get country code corresponding to an IP address 







function get_country_code ($ip) {



$c = curl_init();



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



curl_setopt($c, CURLOPT_HEADER, 1);



curl_setopt($c, CURLOPT_VERBOSE, 1);



curl_setopt($c, CURLOPT_RETURNTRANSFER,1);



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



curl_setopt($c, CURLOPT_ENCODING, 'gzip');



curl_setopt($c, CURLOPT_ENCODING, 'deflate');



curl_setopt($c, CURLOPT_ENCODING, '');



curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);



$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
 
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
 
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!
 
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"
 
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"

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!
 
zone69
perfect, i was just looking for this.
do you think the came could be done with OPENX
and HOW?

thanks
 
zone69
perfect, i was just looking for this.
do you think the came could be done with OPENX
and HOW?

thanks

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.
 
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!!
 
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!!

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.
 
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
 
Is MySQL access faster than opening and reading the flat-file? Also, how effective is the lite version compared to the full version?

Thanks :)
 
Status
Not open for further replies.
Back
Top
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features and essential functions on BlackHatWorld and other forums. These functions are unrelated to ads, such as internal links and images. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock