Go Back   WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk
Register Blogs FAQ Social Groups CalendarHelp Desk

Reply
 
LinkBack Thread Tools
Old 04-13-2009, 04:06 PM   #1
Advanced Warrior
War Room Member
 
PabloVTB's Avatar
 
Join Date: Jan 2009
Posts: 544
Thanks: 155
Thanked 230 Times in 50 Posts
Social Networking View Member's Twitter Profile 
Contact Info
Send a message via AIM to PabloVTB Send a message via Skype™ to PabloVTB
Arrow How can I redirect traffic based on the visitor's country?

How can I redirect traffic based on the visitor's country? The title is quite self-explanatory.
What I want to do is redirect traffic from certain countries to another web page.

More specifically, what I want to do is redirect all the traffic to a web page "X", EXCEPT traffic coming from countries ("A" | "B" | "C"), that will be redirected to another web page "Y".

I've found some possible solutions, such as MaxMind's API: GeoIPCountry (GeoLiteCountry):
MaxMind - GeoIP Apache API

But, I'm a member of BlueHost and they do not support mod_geoip

I'm not sure if that is 100% necessary to make it work, since there are other API's available too (PHP, etc.)

Is there any other way to successfully do this?

Does anyone know where I can get step-by-step instructions on how to do this? I don't really know anything about coding/scripting

Any help would be appreciated. Finding a solution to this is really important for me right now!

Thanks in advance,
Pablo

PabloVTB is offline   Reply With Quote
Old 04-13-2009, 06:47 PM   #2
Advanced Warrior
War Room Member
 
PabloVTB's Avatar
 
Join Date: Jan 2009
Posts: 544
Thanks: 155
Thanked 230 Times in 50 Posts
Social Networking View Member's Twitter Profile 
Contact Info
Send a message via AIM to PabloVTB Send a message via Skype™ to PabloVTB
Tip Re: How can I redirect traffic based on the visitor's country?

Ok, I've been searching a lot and I have found this possible solutions. Both use PHP and GeoLiteCountry data to function:

1) Source: Site 2nd Geoip-php script to redirect user based on country

I got problem to install mod_geoip in my server. So I use the most simple method to redirect users. I just use a php script to do it. Here is a script to redirect user based on their countries by using geoip.dat.
[sourcecode language='php']
/**
* Case Study - GeoIP Redirection
*
* @version $Id$
* @package geoip
* @copyright © 2006 Lampix.net
* @author Dragan Dinic
*/
require_once(”geoip/geoip.inc”);
$gi = geoip_open(”geoip/GeoIP.dat”,GEOIP_STANDARD);
$country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);
if($country_code == ‘CS’)
{
header(”HTTP/1.1 301 Moved Permanently”);
header(’Location: http://www.example.net/1/’);
}
else
{
header(”HTTP/1.1 301 Moved Permanently”);
header(’Location: http://www.example.net/2/’);
}
?>
[/sourcecode]
Change the geoip/geoip.inc and geoip/GeoIP.dat path accordingly.
Change if($country_code == ‘CS’) to your desire country code.
Change header(’Location: http://www.example.net/1/’); to your desire URL.
That’s it! Easy!

2) Source: How-to use maxMind GeoIP for websites | PHP Forums

Sometimes you need to redirect visitors based on the country they come from. Maxmind provides a great country/IP address database in binary format. The following example will show you how redirect visitors from countries which are not on the "whitelist".

Download the latest Geo data and the class file here


Copy the class file and the GeoIP data file into the same directory where the page is located (most of the time the root directory)


Include the class file inside your page and add the following code to request the country using the following code (below the include statements):

$gi = geoip_open('GeoIP.dat', GEOIP_MEMORY_CACHE);
$country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);

Define some country codes the "whitelist":

$my_countries = array('us', 'ca', 'gb', 'fr', 'de', 'nl');

Next place the following code below the $mycountries array:

if (!in_array(strtolower($country), $my_countries)) {
header('Location: some URL...');
exit;
}



=========================================
=========================================

Guys! I did it!


Ok, so, just to let you know, this is how I did it:

I don't really have ANY experience with PHP, but I started searching everywhere to find a solution. And this seems to have worked:

First, I downloaded MaxMind's GeoIP.dat database from here:

http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
Free Version (GeoLiteCountry)

Then I downloaded geoip.inc from here:
http://geolite.maxmind.com/download/.../php/geoip.inc

Then I uploaded those two files to the same directory where my page is located.

I edited my php page and wrote this script inside of it:

Code:
<?php
require_once('geoip.inc');

$gi = geoip_open('GeoIP.dat', GEOIP_MEMORY_CACHE);
$country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);

$my_countries = array('us', 'ca', 'gb', 'fr', 'de', 'nl');
if (!in_array(strtolower($country), $my_countries))
{
header('Location: http://www."ALL"TRAFFICURLGOESHERE.whatever');
}
else
{
header('Location: http://www."SELECTEDCOUNTRIES"URLGOESHERE.whatever');
}
?>
Simply change the country codes you want to target in the line:

$my_countries = array('us', 'ca', 'gb', 'fr', 'de', 'nl');

and the URLs for both the targeted traffic and rest traffic where mentioned.

Country Codes can be found here: MaxMind - ISO 3166 Country Codes

Woalah!
Hope this helps!

PabloVTB is offline   Reply With Quote
Old 05-30-2009, 02:48 PM   #3
SocialAdr.com
War Room Member
 
khtm's Avatar
 
Join Date: Apr 2009
Location: San Diego
Posts: 318
Thanks: 56
Thanked 29 Times in 27 Posts
Social Networking View Member's Myspace Profile  View Member's FaceBook Profile  View Member's Twitter Profile  View Member's YouTube Profile
Default Re: How can I redirect traffic based on the visitor's country?

I just setup the MaxMind free geo redirect script too - works great!

I'm using it to redirect visitors to either Amazon US, Canada, UK, Germany, France, or China.

khtm is offline   Reply With Quote
Old 06-01-2009, 02:20 PM   #4
Warrior Member
 
Join Date: Jan 2009
Location: Canada
Posts: 22
Thanks: 13
Thanked 1 Time in 1 Post
Default Re: How can I redirect traffic based on the visitor's country?

Quote:
Originally Posted by khtm View Post
I just setup the MaxMind free geo redirect script too - works great!

I'm using it to redirect visitors to either Amazon US, Canada, UK, Germany, France, or China.
Did you have to set up multiple associate accounts with Amazon for this?

(Sorry to thread-jack)

Barnsy is offline   Reply With Quote
Old 05-19-2010, 11:23 AM   #5
Warrior Member
 
Join Date: May 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Arrow Re: How can I redirect traffic based on the visitor's country?

Hi guys,

This is exactly what I want... however it doesn't seem to work.

I have uploaded the two files to my site - GeoIP.dat, geoip.inc

I have then added the script to my page...

Now.. does it have to be a PHP file? can it be within a html page? Where does it go? in the <head> section in script tags or the <body> section or what?

It's just not working... can someone help?

Thanks
jjblack is offline   Reply With Quote
Old 08-03-2010, 10:45 AM   #6
Active Warrior
 
Join Date: Aug 2009
Posts: 56
Thanks: 4
Thanked 2 Times in 2 Posts
Social Networking View Member's Twitter Profile 
Default Re: How can I redirect traffic based on the visitor's country?

Anybody have experience with blackhat codebreaker and geolite geoip? I'm trying to implement geoip capability to the bhcb script. Have a problem in the .htaccess rewrite (links.txt -> links.php). It displays the proper links from each country, but still links to the original links.txt instead of using the rewrite links.php country links.
I'm using this concept: Remote Insider Affiliate Marketing Forum - View topic - How to Modify BJ Codebreaker

Any info or suggestions on this??

Buy Facebook Fans - 100% Guaranteed Real FB fans!
unlock iPhone 4s - iPhone Unlocking Solutions for iPhone 4s!
unlock iPhone 4 - iPhone Unlocking Solutions for iPhone 4!
bestofcuba is offline   Reply With Quote
Old 08-03-2010, 12:30 PM   #7
Active Warrior
 
Join Date: May 2009
Posts: 59
Thanks: 1
Thanked 0 Times in 0 Posts
Default Re: How can I redirect traffic based on the visitor's country?

Quote:
Originally Posted by jjblack View Post
Hi guys,

This is exactly what I want... however it doesn't seem to work.

I have uploaded the two files to my site - GeoIP.dat, geoip.inc

I have then added the script to my page...

Now.. does it have to be a PHP file? can it be within a html page? Where does it go? in the <head> section in script tags or the <body> section or what?

It's just not working... can someone help?

Thanks
Must be php..scripts dont work in html..put it on top of the page before html starts

ankit_frenz is offline   Reply With Quote
Old 05-16-2011, 04:03 PM   #8
Warrior Member
 
Join Date: May 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: How can I redirect traffic based on the visitor's country?

Power Redirector seems to be a good redirect script, works with different kind of databases
Deniro is offline   Reply With Quote
Old 05-16-2011, 06:24 PM   #9
<?php echo("Hello"); ?>
 
Join Date: Mar 2011
Location: EU
Posts: 200
Thanks: 3
Thanked 30 Times in 30 Posts
Default Re: How can I redirect traffic based on the visitor's country?

First of all: Grats to Pablo! Its always a great experience to solve a problem totaly on its own, isnt it?

A few more thoughts:

The geomax scripts work fine - however I sometimes encounter little speed problems, but its okay - also I am using the geoip javascript to get visitors info withouth downloading the geoip.dat on my own server and therefor making it a bit slower maybe....

@bestofcuba: keep up the work! i have done almost the same a few years ago when bhcb was just released - so I know for sure it can be done and its a simple task. Unfortunatelly, I think I have lost the files I will try to look for them and pm you if i found them.

However, as far as I can remember, there is no need to add .htaccess rules for redirection. You should think about this:

adding a link to your geo-redirection script inside links.txt -> once a vistors clicks on it -> redirects to geo script -> check country -> redirect to an offer in his country.

hope this helps and i will keep you updated when i find my old files.
andrejvasso is offline   Reply With Quote
Old 05-18-2011, 03:38 AM   #10
Active Warrior
 
Vincent1988's Avatar
 
Join Date: May 2011
Posts: 86
Thanks: 3
Thanked 3 Times in 3 Posts
Contact Info
Send a message via AIM to Vincent1988 Send a message via MSN to Vincent1988 Send a message via Skype™ to Vincent1988
Default Re: How can I redirect traffic based on the visitor's country?

Quote:
Originally Posted by Deniro View Post
Power Redirector seems to be a good redirect script, works with different kind of databases
I too used this one, but got some problems with my server. Do you have a demo?

Looking for a serious JV partnership. Pm me
Vincent1988 is offline   Reply With Quote
Old 10-02-2011, 06:02 PM   #11
Warrior Member
 
Snatch's Avatar
 
Join Date: Jul 2009
Posts: 27
Thanks: 2
Thanked 0 Times in 0 Posts
Default Re: How can I redirect traffic based on the visitor's country?

Quote:
Originally Posted by jjblack View Post
Hi guys,

This is exactly what I want... however it doesn't seem to work.

I have uploaded the two files to my site - GeoIP.dat, geoip.inc

I have then added the script to my page...

Now.. does it have to be a PHP file? can it be within a html page? Where does it go? in the <head> section in script tags or the <body> section or what?

It's just not working... can someone help?

Thanks
I have the same question...anybody????..........................
Snatch is offline   Reply With Quote
Reply

  WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk

Tags
based, country, redirect, traffic, visitor

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 11:48 PM.