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

 

 

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.