473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Showing script based on the country

I have a few javascripts. I would like to show a certain script based on
the country ip of the viewer, how would I achieve this? is there html I
could use to run the javascript based on the country ip?
Jul 4 '06 #1
10 2148
Nospam wrote:
I have a few javascripts. I would like to show a certain script based on
the country ip of the viewer, how would I achieve this? is there html I
could use to run the javascript based on the country ip?

You can't do it reliably. All you can do is take a guess at the country of the
ip connecting to you, and that won't always be accurate. Plus they might be
using a proxy anyplace in the world.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 4 '06 #2
On Mon, 03 Jul 2006 22:22:08 -0400, Jerry Stuckle put finger to
keyboard and typed:
>Nospam wrote:
>I have a few javascripts. I would like to show a certain script based on
the country ip of the viewer, how would I achieve this? is there html I
could use to run the javascript based on the country ip?


You can't do it reliably. All you can do is take a guess at the country of the
ip connecting to you, and that won't always be accurate. Plus they might be
using a proxy anyplace in the world.
That's true, but it's not quite as bad as you make it sound. Freely
available Geo-IP databases will give over 95% accuracy, which is
usually enough for most purposes. Proxies aren't really a major issue,
as almost all well-configured proxies will pass the originating IP on
in the HTTP-FORWARDED-FOR header. Those that don't are generally those
which are deliberately designed to anonymise the origin, and that's
fairly rare.

The main problem is AOL, which will always appear as the US
irrespective of the user's actual location, as AOL configures all its
worldwide addresses from the same US-allocated pool. To get accurate
geo-location of AOL users, therefore, you need access to AOL's
internal database, and that isn't available for free. Some commercial
products include it (as well as other ISP cross-border databases), and
with that level of detail you can get over 99% accuracy - provided
you're prepared to pay for it.

To go back to the OP's question, Geo-IP detection is best done
server-side using a combination of scripting and a database, as you're
going to need to cross-check against a quite large amount of data.
It's pretty trivial with most server-side scripting/database
combinations, such as PHP/MySQL or ASP/MSSQL, but you do need a
certain familiarity with these in order to use them. If you don't want
to run your own database, I'd suggest using the freeware binary data
from MaxMind, together with one of their supplied APIs in the
scripting language of your choice:

http://www.maxmind.com/app/geoip_country

Mark
--
Visit: http://names.orangehedgehog.com - British surname distribution profiles
Listen: http://www.goodge.co.uk/files/dweeb.mp3 - you'll love it!
Jul 4 '06 #3
To further the education of mankind, Jerry Stuckle
<js*******@attglobal.netvouchsafed:
Nospam wrote:
>I have a few javascripts. I would like to show a certain script
based on the country ip of the viewer, how would I achieve this? is
there html I could use to run the javascript based on the country ip?


You can't do it reliably. All you can do is take a guess at the
country of the ip connecting to you, and that won't always be
accurate. Plus they might be using a proxy anyplace in the world.
Yeah. One time I used a proxy in Biloxi to chat with some foxy with the
moxie in Bayonne...

--
Neredbojias
Infinity has its limits.
Jul 4 '06 #4
JRS: In article <Gv******************************@comcast.com>, dated
Mon, 3 Jul 2006 22:22:08 remote, seen in news:comp.lang.javascript,
Jerry Stuckle <js*******@attglobal.netposted :
>Nospam wrote:
>I have a few javascripts. I would like to show a certain script based on
the country ip of the viewer, how would I achieve this? is there html I
could use to run the javascript based on the country ip?
>You can't do it reliably. All you can do is take a guess at the country of the
ip connecting to you, and that won't always be accurate. Plus they might be
using a proxy anyplace in the world.
Plus it may not be relevant. A substantial proportion of people
hereabouts, both in this district and in this building, are of non-UK
origin and may well prefer to be treated as if in another country.

Then many of those using Internet cafes are just passing through the
area.

If you are required to be selective, then javascript is not the tool,
and the task may be impossible; otherwise, let the user choose.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 4 '06 #5
Nospam <no****@home.comscripsit:
I have a few javascripts. I would like to show a certain script
based on the country ip of the viewer, how would I achieve this? is
there html I could use to run the javascript based on the country ip?
Why would you _show_ a certain script?

In almost all cases like this, an analysis of the problem reveals that it's
not really about country but language. So the problem definition is wrong,
and we don't even need to consider all the pitfalls in solving the wrong
problem.

In any case, telling the _real_, original problem and illustrating it with a
URL would at least give you a working chance of getting a useful solution.

F'ups trimmed.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Jul 4 '06 #6
Nospam schrieb:
I have a few javascripts. I would like to show a certain script based on
the country ip of the viewer, how would I achieve this? is there html I
could use to run the javascript based on the country ip?

Another solution would be to write everything in one script but call
different functions according to the language. The advantage would be
that you can use JS to get the language selected in the browser:

var lang;
if (navigator.browserLanguage) lang=navigator.browserLanguage; //IE
else if (navigator.language) lang=navigator.language; //others

or, shortend:

var lang=(navigator.browserLanguage) ? navigator.browserLanguage :
navigator.language;
Jul 5 '06 #7
jojo <jo*********@gmx.descripsit:
Nospam schrieb:
>I have a few javascripts. I would like to show a certain script
based on the country ip of the viewer, how would I achieve this? is
there html I could use to run the javascript based on the country ip?

Another solution would be to write everything in one script but call
different functions according to the language.
Solution to what? Surely not to the question that was asked, though perhaps
to the question that the OP _meant_ to ask. It's probably still the wrong
question.
The advantage would be
that you can use JS to get the language selected in the browser:
No, it is a definite _disadvantage_, since now you would not even try to
select the user's preferred language but the language of the browser's
interface. This language is very often English even though the user knows
just a little English and prefers quite other languages. The simple reason
is that many browsers (especially new versions) are available as English
versions only.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Jul 6 '06 #8
Jukka K. Korpela schrieb:
jojo <jo*********@gmx.descripsit:
>Nospam schrieb:
>>I have a few javascripts. I would like to show a certain script
based on the country ip of the viewer, how would I achieve this? is
there html I could use to run the javascript based on the country ip?

Another solution would be to write everything in one script but call
different functions according to the language.

Solution to what? Surely not to the question that was asked, though
perhaps to the question that the OP _meant_ to ask. It's probably still
the wrong question.
>The advantage would be
that you can use JS to get the language selected in the browser:

No, it is a definite _disadvantage_, since now you would not even try to
select the user's preferred language but the language of the browser's
interface. This language is very often English even though the user
knows just a little English and prefers quite other languages. The
simple reason is that many browsers (especially new versions) are
available as English versions only.
ASFAIK the JS-properties I suggested provide the language the user set
as his preferred language. In most browsers (IE, Firefox, Netscape,
Opera, ...) there is an option to select your preferred languages (_any_
language you like to, no matter in which language the browsers interface
is).
So it is even better using this properties than the IP because if, lets
say a German, is in the USA he has got an American IP. But perhaps he
still wants to view the websites in German...
Jul 6 '06 #9
jojo <jo*********@gmx.descripsit:

[ pointless fullquote - the usual signal of lack of comprehensive reading ]
ASFAIK the JS-properties I suggested provide the language the user set
as his preferred language.
"ASFAIK"? So you never actually tested it?
In most browsers (IE, Firefox, Netscape,
Opera, ...) there is an option to select your preferred languages
(_any_ language you like to, no matter in which language the browsers
interface is).
Yes. And this setting has, unfortunately, rather limited effect, since so
few servers try to make use of it. Besides, the setting is often wrong: it
reflects browser defaults rather than user preferences.

And the method you suggested does not fetch that setting but the browser's
interface language. Try it. Select any languages you like in the language
preferences and see what your code produces: not a string of language
preference list, or the first language in the list, or the language with the
highest quality factor. Instead, you get "en" if your browser interface is
English.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Jul 8 '06 #10
You might want to considerIP2Location as well.

http://www.ip2location.com

Jul 29 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Chuck Amadi | last post by:
Sorry to bovver you again (again) here's script. I still can't see why the get_payload() doesn't produce the plain text message body of an emails in the testwwws users mailbox. As you can see I...
2
by: MC | last post by:
I am writing a script to retrieve data records of MarinLif table. The problem is that i have a column MarinLif_Picture of type image so the insert is wrong in this way. How do i correct it? ...
5
by: - | last post by:
Hi all, I want to create an sql script and one of the table that will be created is a 'country' table. The question is how do I populate the country tables? Should there be individual INSERT...
2
by: Jason Brown | last post by:
I can't find any javascript that displays a banner according to a user's country. Is this not possible? If not javascript then maybe php or ssi displayed into a page via an iframe. Does anyone...
33
by: Nigel Molesworth | last post by:
I've Googled, but can't find what I need, perhaps I asking the wrong question! I want a "FAQ" page on a web site, I hate those pages that scroll you to the answer so and I figured that a good...
2
by: Jeff Barry | last post by:
Hi, I wonder if any one can help, I'm pretty new to Access and I can't figure out how to change the contents of a combo box based on a selection I make in another. Let me explain I have a...
2
by: phptriad | last post by:
:confused: Allo buddy does any one know how ti fix this.. I was sent email using mail(...) and the message email was succesed, but when the server in my Internet Provider has trouble.... the message...
1
by: Grimm | last post by:
I am developing an internalk inteface that integrates alot of seperate tools into one interface. The current version uses one Iframe inside a div layer for positioning. Currently the seperate web...
3
by: alandiit | last post by:
Hi every body I would like connect three combo box (CascadingDropDown with a Database) MYSQL by asp classic or Java Script . But I have a problem with this example , when I will change City ,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.