Need Someone To Code For Me PHP Geo-Targetting

Status
Not open for further replies.
Instead of using
Code:
 case "US": header("Location: http://Your_American_page"); break;

can i use like

Code:
 case "US": echo "<a href="http://Your_American_page">
<img src="http://Your_American_page/image.jpg"/></a>"; break;


to target banner ads?

and also I have ip2nation in my mysql database. I think it requires same coding?




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!
 
zone69's script still works great..

Does anyone have the skills to incorporate a url rotator to each of the country lines?
 
How about this quick and dirty solution:

Create a text file, 1 url per line for each country like UK.txt, CA.txt, US.txt, AU.txt and DEFAULT.txt, and replace switch section with this:
PHP:
	$countries=array('UK' => 'UK', 'US' => 'US', 'CA' => 'CA', 'AU' => 'AU');
	$linksfile = (isset($countries[$country_code])) ? ($country_code . '.txt') : 'DEFAULT.txt';
	$urls = file("$linksfile");
	$url = rand(0, sizeof($urls)-1);
	$goto = "$urls[$url]";
	header("Location: $goto");

untested but should work
 
Last edited:
Instead of using
Code:
 case "US": header("Location: http://Your_American_page"); break;

can i use like

Code:
 case "US": echo "<a href="http://Your_American_page">
<img src="http://Your_American_page/image.jpg"/></a>"; break;


to target banner ads?

just use iframes with banner codes on them. tested and it's working :)
 
It's GB. Not UK as the examples above state, just be sure you double check that. I was trying to figure it out for hours why it was not working for me, but a simple solution.
 
how would i add places like denmark, spain, norway? i am not sure they are even in the database?
 
Last edited:
Hey,

Just one quick question if a guy from canada was to hit the UK page does it bounce back to the correct page for all of you? It doesn't seem to be doing it for me.
 
This thread is very old, but thanks for bumping it...it saved my day... :D
 
Ohh now I have a problem...

I tried to use this script with a DMR, but when I use Neverblue links, I always get a "The parameter "c" is not specified" error. :confused:

Here's what I use:
Code:
<?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://www.XXX.info/goto/globalrefresh.php?ourl=http://www.mb01.com/lnk.asp?o=666&c=555&a=444"); break;
        case "CA": header("Location: http://www.XXX.info/goto/globalrefresh.php?ourl=http://www.mb01.com/lnk.asp?o=111&c=222&a=333"); break;
    case "GB": header("Location: http://www.XXX.info/goto/globalrefresh.php?ourl=http://www.mb01.com/lnk.asp?o=111&c=777&a=888"); break;
    case "SE": header("Location: http://www.XXX.info/goto/globalrefresh.php?ourl=http://www.mb01.com/lnk.asp?o=999&c=123&a=476"); break;
    case "AU": header("Location: http://www.XXX.info/goto/globalrefresh.php?ourl=http://fbgdc.com/click/?s=1234&c=654323"); break;
        default: header("Location: http://www.XXX.info/goto/globalrefresh.php?ourl=http://jxliu.com/click/?s=15433&c=456544");
}
?>
Here's the DMR code globalrefresh.php
Code:
<?php
$offerurl = $_GET['ourl'];
echo "<meta http-equiv=\"refresh\" content=\"0;url=http://www.XXX.info/goto/check.php?ourl=$offerurl\">";
?>
check.php
Code:
<?php

    $referer = $_SERVER['HTTP_REFERER'];

    if($referer == "")

      {
        $offerurl = $_GET['ourl'];
        echo "<meta http-equiv=\"refresh\" content=\"0;url=$offerurl\">";

      }

    else

    {

        echo "<meta http-equiv=\"refresh\" content=\"0;url=http://www.XXXX.com/\">";

    }



?>
Can anyone help me with this???
 
Not sure, but you can try to encode the URL.

Its likely the & in the URL which is %26 encoded.

Just past your URL in here to and click encode to encode all unsafe characters in the URL to be safe:
Code:
http://meyerweb.com/eric/tools/dencoder/


Hope that works for you
 
Last edited:
Thanks for your answer, but this doesn't work...

The browser doesn't accept the URL when I encode it...

Anyone else have a solution for my problem?

I found out, that it works when I start with the DMR script and then call the geo script.
But is it safe to make a DMR and after that redirect from my geoscript above?
Doesn't it leak the referrer because I call another site on my server after the DMR?


EDIT: I checked it now with converting the nb aff. link to a tinyurl and it works with my DMR.

Code:
default: header("Location: http://www.XXX.info/goto/globalrefresh.php?ourl=[B]http://t*nyURL.com/434545[/B]");
So it has something to do with the character. I have to encode it in someway, but zone69's encoder didn't work.
 
Last edited:
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!

this help alot! great share and a thanks to OP!
 
Status
Not open for further replies.
Back
Top