NameSilo

Redirect users by country

Spaceship Spaceship
Watch

w1ww

Established Member
Impact
9
Im wondering if a script exists that can detect the country of origin and redirect the user to another page of my site...

example:

All United States users go to /us
All UK users go to /uk
And so on ........

Thank you
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
You'll need a large IP database/array which are available usually for a fee. Then the rest is up to a simple PHP script.
 
0
•••
Hm, or by checking the language or something !

I don't really want to pay for it ..

But thanks for you suggestion! :)
 
0
•••
I believe there are free versions around I'll take a look and see if I can find some :D
 
0
•••
Get a database from
Download geoip.zip
I uploaded the free database and scripts.

Inside you will see the database file GeoIP.dat and a geoip.inc.php file.

Create a new PHP file and insert the following code

PHP:
<?php
include("geoip.inc"); // include the geoip functions
$geofile = geoip_open("GeoIP.dat",GEOIP_STANDARD); // open the geoip data file
$geo = geoip_country_code_by_addr($geofile, $_SERVER['REMOTE_ADDR']);
geoip_close($geofile); // close the data file

// Do a switch function and redirect to different areas
switch ($geo) {
case "US":
// Redirect to US part
header("location: gbpart.php");
break;

case "GB":
// Redirect to UK part
header("location: gbpart.php");
break;

case "CA":
// Redirect to Canadian part
header("location: capart.php");
creak;

case "NL":
// Redirect to Netherlands part
header("location: nlpart.php");
break;

// Etc etc.. Make sure to use the 2 letter country code. If you need a list you can open geo.inc.php and look for the HUGE array
}
?>

If you need to redirect ALL countries to there parts
You can just forget the switch clause and just do a simple
header("location: http://yoursite.com/$cc");
Which will redirect ALL visitors to there seperate sections. For a list of the countries CC below.

Code:
"AP", "EU", "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AN", "AO", "AQ",
"AR", "AS", "AT", "AU", "AW", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH",
"BI", "BJ", "BM", "BN", "BO", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA",
"CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU",
"CV", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG",
"EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "FX", "GA", "GB",
"GD", "GE", "GF", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT",
"GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IN",
"IO", "IQ", "IR", "IS", "IT", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM",
"KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS",
"LT", "LU", "LV", "LY", "MA", "MC", "MD", "MG", "MH", "MK", "ML", "MM", "MN",
"MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA",
"NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA",
"PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY",
"QA", "RE", "RO", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI",
"SJ", "SK", "SL", "SM", "SN", "SO", "SR", "ST", "SV", "SY", "SZ", "TC", "TD",
"TF", "TG", "TH", "TJ", "TK", "TM", "TN", "TO", "TP", "TR", "TT", "TV", "TW",
"TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN",
"VU", "WF", "WS", "YE", "YT", "CS", "ZA", "ZM", "ZR", "ZW", "A1", "A2", "O1"

- Steve
 
Last edited:
1
•••
Wow, thanks iNod I'll try it! But tell me, How can I do an If clause to all the users from countries that dont have a specific part on the website?

something like:

Code:
default:
header("location: world.php");
break;
?



Thank you! +Rep

Oh, and please upload the file elsewhere .. I can't download it.. It just stays loading and loading! :\

Thanks again!

iNod said:
Get a database from
Download geoip.zip
I uploaded the free database and scripts.

Inside you will see the database file GeoIP.dat and a geoip.inc.php file.

Create a new PHP file and insert the following code

PHP:
<?php
include("geoip.inc"); // include the geoip functions
$geofile = geoip_open("GeoIP.dat",GEOIP_STANDARD); // open the geoip data file
$geo = geoip_country_code_by_addr($geofile, $_SERVER['REMOTE_ADDR']);
geoip_close($geofile); // close the data file

// Do a switch function and redirect to different areas
switch ($geo) {
case "US":
// Redirect to US part
header("location: gbpart.php");
break;

case "GB":
// Redirect to UK part
header("location: gbpart.php");
break;

case "CA":
// Redirect to Canadian part
header("location: capart.php");
creak;

case "NL":
// Redirect to Netherlands part
header("location: nlpart.php");
break;

// Etc etc.. Make sure to use the 2 letter country code. If you need a list you can open geo.inc.php and look for the HUGE array
}
?>

If you need to redirect ALL countries to there parts
You can just forget the switch clause and just do a simple
header("location: http://yoursite.com/$cc");
Which will redirect ALL visitors to there seperate sections. For a list of the countries CC below.

Code:
"AP", "EU", "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AN", "AO", "AQ",
"AR", "AS", "AT", "AU", "AW", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH",
"BI", "BJ", "BM", "BN", "BO", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA",
"CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU",
"CV", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG",
"EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "FX", "GA", "GB",
"GD", "GE", "GF", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT",
"GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IN",
"IO", "IQ", "IR", "IS", "IT", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM",
"KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS",
"LT", "LU", "LV", "LY", "MA", "MC", "MD", "MG", "MH", "MK", "ML", "MM", "MN",
"MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA",
"NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA",
"PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY",
"QA", "RE", "RO", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI",
"SJ", "SK", "SL", "SM", "SN", "SO", "SR", "ST", "SV", "SY", "SZ", "TC", "TD",
"TF", "TG", "TH", "TJ", "TK", "TM", "TN", "TO", "TP", "TR", "TT", "TV", "TW",
"TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN",
"VU", "WF", "WS", "YE", "YT", "CS", "ZA", "ZM", "ZR", "ZW", "A1", "A2", "O1"

- Steve
 
Last edited:
0
•••
its also helpful fro me
 
0
•••
0
•••
Ok, I have it working thanks guys :)!!
 
0
•••
Appraise.net

We're social

Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back