NameSilo

IP related content

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch
Impact
19
Hey
how do you determine the origin of your viewers IP and then loading the stuff you have for that country?
for example..if its a Chineese IP i want to include a different file then if the viewer has an IP from Canada

Thanks
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
There are a couple of things you could do. For example you could use a database such as http://www.ip2location.com/ (that's a paid for database but there are free ones).

Alternatively you could use the accepted language header sent from the browser (although this is not a very good method).
 
0
•••
It's easy: capture the IP of the visitor

PHP:
<?php
echo $_SERVER['REMOTE_ADDR'];
?>
then look up the IP against a database.
For example the Geolite country DB from is fine if you just need the country with 99% accuracy.
 
0
•••
is that how awstat tells you where your visitors are coming from?
also do i really need the entire db?
because i just want to determine if the user is coming from China and then send them out to the website in chineese instead of them having using my server
sdsinc said:
It's easy: capture the IP of the visitor

PHP:
<?php
echo $_SERVER['REMOTE_ADDR'];
?>
then look up the IP against a database.
For example the Geolite country DB from is fine if you just need the country with 99% accuracy.
 
0
•••
if you want it ONLY for chinese (or whatever country), you could pull out just those IP ranges from the database and then do the check for "is within chinese range" or "is not within chinese range" and do it like that. it would probably save server processing as it wouldn't have to query a database.


also, if you're going to do this, to save yourself the trouble of installign it to an mysql database, just open the .csv file in excel and view it like that.
 
0
•••
nasaboy007 said:
if you want it ONLY for chinese (or whatever country), you could pull out just those IP ranges from the database and then do the check for "is within chinese range" or "is not within chinese range" and do it like that. it would probably save server processing as it wouldn't have to query a database.


also, if you're going to do this, to save yourself the trouble of installign it to an mysql database, just open the .csv file in excel and view it like that.
doesnt that take alot of server resources? to look through the database each time someone visits my website?
 
0
•••
unknowngiver said:
doesnt that take alot of server resources? to look through the database each time someone visits my website?
A quick and dirty way (I don't know how accurate this would be) is to see if their host name ends in .cn.
 
0
•••
i'd imagine it does take a lot of server resources if you are looking up their IP every time (and you're using the whole database), but i'm sure that admins use methods to reduce the strain. the first thing that would come to mind is that when a user visits for the FIRST time, their location is looked up via the database, and then that is stored within a cookie, and henceforth, the cookie is used to redirect the user rather than another db query.

but what i was saying was that if you only want to match it to a few ranges, you could just hardcode that check in, so all db queries are eliminated. then, you could optionally use the cookie thing but i think that if you're only checking a few ranges (as opposed to hundreds), it would be the same speed, whether u recalculate or use cookies.
 
0
•••
nasaboy007 said:
i'd imagine it does take a lot of server resources if you are looking up their IP every time (and you're using the whole database), but i'm sure that admins use methods to reduce the strain. the first thing that would come to mind is that when a user visits for the FIRST time, their location is looked up via the database, and then that is stored within a cookie, and henceforth, the cookie is used to redirect the user rather than another db query.

but what i was saying was that if you only want to match it to a few ranges, you could just hardcode that check in, so all db queries are eliminated. then, you could optionally use the cookie thing but i think that if you're only checking a few ranges (as opposed to hundreds), it would be the same speed, whether u recalculate or use cookies.
when you say hardcode you mean i will have to save all the "China" ips in an array and then check if the the users IP is in that array?
 
0
•••
or at least put the China ip ranges in an array (if there are multiple ranges in the database for china, i didn't look) and then check if the user's ip falls within any of those ranges (using the method that they gave as an example on the site).
 
0
•••
Have you tried just checking the hostname?
 
0
•••
mholt said:
Have you tried just checking the hostname?
no there is no way for me to confirm it since i dont know anyone from china
 
0
•••
unknowngiver said:
no there is no way for me to confirm it since i dont know anyone from china

But if it ends in .cn, isn't that a pretty good indicator that they are from China?
 
0
•••
Appraise.net

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

Parking: find your domains by pasting a list
You can now paste a list of domain names into the search box at the top of the Parking menu. Put one name on each line. Your domain list...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back