Jump to content

How to automatically redirect users according to their ip?


vinnier

Recommended Posts

Hi,

 

Does anyone know a way to redirect users to a certain subpage based on their ip? You know like when sometimes you got to www.samplewebsite.com and it knows that you are from the UK it redirects you to www.samplewebsite.com/uk

and when a user from russia tries to access the website he is redirected to www.samplewebiste.com/ru

 

 

Thanks. Coulnd't find geoip for free, but found a way to redirect simply by htaccess;

 

RewriteCond %{REMOTE_ADDR} ^64\.126\.81\.30$ [OR]
RewriteCond %{REMOTE_ADDR} ^75\.117\.244\.27$
RewriteRule .* http://www.usdoj.gov/criminal/cybercrime/cyberstalking.htm [R,L]

 

 

My question now is, where do I find IPs of all countries? So that I can put in 00.000.000.XXX as a range of ip all for example belonging to Russia. Otherwise I would have to put every single ip separately which would simply be undoable ;)

There are plenty of free APIs out there.

 

You can do grab

http://api.hostip.info/get_html.php?ip=12.215.42.19

with PHP and it will return something like this

Country: UNITED STATES (US)
  City: Sugar Grove, IL
IP: 12.215.42.19

 

You can check out http://www.hostip.info/use.html for more information.

 

One problem is the GeoIP stuff isn't always accurate.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.