[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 12-21-2006, 04:35 PM   #1 (permalink)
NamePros Regular
 
w1ww's Avatar
 
Join Date: Oct 2006
Location: Mars.
Posts: 433
109.50 NP$ (Donate)

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, 04:43 PM   #2 (permalink)
NamePros Regular
 
Tree's Avatar
 
Join Date: Feb 2006
Location: Atlanta, GA, USA
Posts: 335
13.25 NP$ (Donate)

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, 05:17 PM   #3 (permalink)
NamePros Regular
 
w1ww's Avatar
 
Join Date: Oct 2006
Location: Mars.
Posts: 433
109.50 NP$ (Donate)

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, 08:20 PM   #4 (permalink)
NamePros Regular
 
baxter's Avatar
 
Join Date: Apr 2006
Posts: 289
1,990.00 NP$ (Donate)

baxter is a jewel in the roughbaxter is a jewel in the roughbaxter is a jewel in the rough

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
__________________
Chimps.ca - Swans.ca - Snails.ca
baxter is offline  
Old 12-21-2006, 09:43 PM   #5 (permalink)
Eating Pie
 
iNod's Avatar
 
Join Date: Nov 2004
Location: Canada
Posts: 2,289
126.05 NP$ (Donate)

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":
// 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 09:46 PM.
iNod is offline  
Old 12-22-2006, 04:40 AM   #6 (permalink)
NamePros Regular
 
w1ww's Avatar
 
Join Date: Oct 2006
Location: Mars.
Posts: 433
109.50 NP$ (Donate)

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!

Quote:
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
}
?>
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 04:56 AM.
w1ww is offline  
Old 12-22-2006, 05:00 AM   #7 (permalink)
NamePros Member
 
letsjoy's Avatar
 
Join Date: Aug 2005
Location: █ Pakistan █
Posts: 105
22.95 NP$ (Donate)

letsjoy is an unknown quantity at this point


its also helpful fro me
letsjoy is offline  
Old 12-22-2006, 05:08 AM   #8 (permalink)
Ultima Ratio Regum
 
Redleg's Avatar
 
Join Date: Sep 2003
Location: Up North
Posts: 2,083
71.00 NP$ (Donate)

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 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..
__________________
|Internet, Games, Computer Talk|IP Whois + Geolocation|Geolocate your IP|
|Dynamic Forum Sigs|2,900+ Free Flash Games|

<meta name="Jedi Mind Trick" content="Buy my domains, you will!">
VoIPUSA.com-MyBlogging.com-ArrivingSoon.com-Nano.tv- Technology.ws-Ammo.us-Racing.cc-Privacy.ws
Redleg is offline  
Old 12-22-2006, 06:15 AM   #9 (permalink)
NamePros Regular
 
w1ww's Avatar
 
Join Date: Oct 2006
Location: Mars.
Posts: 433
109.50 NP$ (Donate)

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

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 On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 10:47 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85