NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Redirect users by country

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 12-21-2006, 05:35 PM THREAD STARTER               #1 (permalink)
NamePros Regular
 
w1ww's Avatar
Join Date: Oct 2006
Location: Mars.
Posts: 439
w1ww is a jewel in the roughw1ww is a jewel in the roughw1ww is a jewel in the rough
 



Redirect users by country


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
__________________
:notme:
w1ww is offline  
Old 12-21-2006, 05:43 PM   #2 (permalink)
NamePros Regular
 
Tree's Avatar
Join Date: Feb 2006
Location: Atlanta, GA, USA
Posts: 335
Tree will become famous soon enoughTree will become famous soon enough
 



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.
Tree is offline  
Old 12-21-2006, 06:17 PM THREAD STARTER               #3 (permalink)
NamePros Regular
 
w1ww's Avatar
Join Date: Oct 2006
Location: Mars.
Posts: 439
w1ww is a jewel in the roughw1ww is a jewel in the roughw1ww is a jewel in the rough
 



Hm, or by checking the language or something !

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

But thanks for you suggestion!
__________________
:notme:
w1ww is offline  
Old 12-21-2006, 09:20 PM   #4 (permalink)
NamePros Regular
 
baxter's Avatar
Join Date: Apr 2006
Posts: 363
baxter is just really nicebaxter is just really nicebaxter is just really nicebaxter is just really nice
 


Ethan Allen Fund Save The Children
I believe there are free versions around I'll take a look and see if I can find some
__________________
Canadian Domain Registrar Ready.ca
baxter is offline  
Old 12-21-2006, 10:43 PM   #5 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,272
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
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 Code:
<?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":
????: NamePros.com http://www.namepros.com/programming/271816-redirect-users-by-country.html
// 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
__________________
I feel old.
Last edited by iNod; 12-21-2006 at 10:46 PM.
iNod is offline  
Old 12-22-2006, 05:40 AM THREAD STARTER               #6 (permalink)
NamePros Regular
 
w1ww's Avatar
Join Date: Oct 2006
Location: Mars.
Posts: 439
w1ww is a jewel in the roughw1ww is a jewel in the roughw1ww is a jewel in the rough
 



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!

Originally Posted by iNod
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 Code:
<?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
????: NamePros.com http://www.namepros.com/showthread.php?t=271816
}
?>
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
__________________
:notme:
Last edited by w1ww; 12-22-2006 at 05:56 AM.
w1ww is offline  
Old 12-22-2006, 06:00 AM   #7 (permalink)
NamePros Member
 
letsjoy's Avatar
Join Date: Aug 2005
Location: █ P4!N █
Posts: 119
letsjoy is on a distinguished road
 



its also helpful fro me
letsjoy is offline  
Old 12-22-2006, 06:08 AM   #8 (permalink)
Ultima Ratio Regum
 
Redleg's Avatar
Join Date: Sep 2003
Location: Up North
Posts: 2,082
Redleg is a splendid one to beholdRedleg is a splendid one to beholdRedleg is a splendid one to beholdRedleg is a splendid one to beholdRedleg is a splendid one to beholdRedleg is a splendid one to beholdRedleg is a splendid one to beholdRedleg is a splendid one to behold
 



You can also find a free (and pretty good) IP to country database here:
http://ip-to-country.webhosting.info/node/view/6

There are also some examples in there how to use it..
__________________
IP Whois + Geolocation|Geolocate your IP|Dynamic Forum Sigs
<meta name="Jedi Mind Trick" content="Buy my domains, you will!">
Redleg is offline  
Old 12-22-2006, 07:15 AM THREAD STARTER               #9 (permalink)
NamePros Regular
 
w1ww's Avatar
Join Date: Oct 2006
Location: Mars.
Posts: 439
w1ww is a jewel in the roughw1ww is a jewel in the roughw1ww is a jewel in the rough
 



Ok, I have it working thanks guys !!
__________________
:notme:
w1ww is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 11:20 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger