Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you redirect based on IP address?

Status
Not open for further replies.

meeble3

Programmer
Nov 8, 2004
52
GB
So I want to automatically forward people to a page depending on what country they are from.

So if they are from America they go to page one, Canada page 2 etc.

How do you do this? Is there a website that shows the IP range for each country in the world?

How accurate is it doing it like this?

Thanks...

 
If I my memory don't fails me, you can do it with javascript... don't remember exact code but you could search in the web.

Basically what the javascript does is ask to the user PC (or browser) regarding the local seting (locales), so if your PC is set for an i.e. french locales, so it redirect the user to a french site.

**
With a quick search I found something that can guide you, it redirects according to the language settings:

Code:
Find the language setting of the brwoser

Determine the user's language setting and redirect to the appropriate language homepage


<SCRIPT LANGUAGE="JavaScript1.2">
<!-- Begin
if (navigator.appName == 'Netscape')
var language = navigator.language;
else
var language = navigator.browserLanguage;
if (language.indexOf('en') > -1) document.location.href = 'English.html';
else if (language.indexOf('nl') > -1) document.location.href = 'dutch.html';
else if (language.indexOf('fr') > -1) document.location.href = 'french.html';
else if (language.indexOf('de') > -1) document.location.href = 'german.html';
else if (language.indexOf('ja') > -1) document.location.href = 'japanese.html';
else if (language.indexOf('it') > -1) document.location.href = 'italian.html';
else if (language.indexOf('pt') > -1) document.location.href = 'portuguese.html';
else if (language.indexOf('es') > -1) document.location.href = 'Spanish.html';
else if (language.indexOf('sv') > -1) document.location.href = 'swedish.html';
else if (language.indexOf('zh') > -1) document.location.href = 'chinese.html';
else
document.location.href = 'English.html';
//   -->
</script>

this code comes from
 
Thanks but how does it tell America from Canada or Britain? They all speak English...
 
you can use the incoming server variable and then use an external library to link to the country of the tld. i believe that there are some (free) perl libraries that do this. also have a look at (which sell a service to do this - I have no affiliation for the avoidance of doubt)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top