/    Sign up×
Community /Pin to ProfileBookmark

GeoIP location with javascript

I’ve found a way to do this in PHP, but I need to know if it is possible to do in javascript:

[B]PHP:[/B]

[CODE]$ip = ($_SERVER[“REMOTE_ADDR”]);
$country = file_get_contents(“http://api.hostip.info/country.php?ip=”.$ip);[/CODE]

How could I do this in Javascript?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayJan 17.2009 — Javascript can't read outside of it's domain so you will still will need something like that server side to read another site, but you could use AJAX to communicate with the server side code.
Copy linkTweet thisAlerts:
@transparenciaauthorJan 17.2009 — Hmmm, ok. Could I use Javascript to connect to a PHP file and then execute server-side code?

The reason I ask this is that I have an index.html page and I want to run this particular code in it. But for that I would have to change its extension to PHP, and I don't want to do that because I would lose some inbound links as well as the site would have to be completely remodeled.

PS: I tried using .htaccess to make HTML executed like PHP, but no luck.
Copy linkTweet thisAlerts:
@TheBearMayJan 17.2009 — Correct.
×

Success!

Help @transparencia spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...