vinnier Posted March 11, 2010 Share Posted March 11, 2010 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 Quote Link to comment Share on other sites More sharing options...
trq Posted March 11, 2010 Share Posted March 11, 2010 Ips can be found within the $_SERVER array & you can redirect using header. As for redirecting based on location (is that what your actually asking?) you will need to look into geoip (Google it). Quote Link to comment Share on other sites More sharing options...
vinnier Posted March 11, 2010 Author Share Posted March 11, 2010 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 Quote Link to comment Share on other sites More sharing options...
XeNoMoRpH1030 Posted March 11, 2010 Share Posted March 11, 2010 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. Quote Link to comment Share on other sites More sharing options...
vinnier Posted March 12, 2010 Author Share Posted March 12, 2010 Thanks but all of this is confusing me... I am not a pro in those things. Allow me to kindly ask you to tell me how to get my website to geolocate and redirect users according to their ip? Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 12, 2010 Share Posted March 12, 2010 This is the free geoIP csv file http://www.maxmind.com/app/geolitecountry HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.