Author Topic: How to automatically redirect users according to their ip?  (Read 741 times)

0 Members and 1 Guest are viewing this topic.

Offline vinnierTopic starter

  • Enthusiast
  • Posts: 56
    • View Profile
How to automatically redirect users according to their ip?
« on: March 11, 2010, 07:22:04 AM »
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


Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: How to automatically redirect users according to their ip?
« Reply #1 on: March 11, 2010, 07:33:32 AM »
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).

Offline vinnierTopic starter

  • Enthusiast
  • Posts: 56
    • View Profile
Re: How to automatically redirect users according to their ip?
« Reply #2 on: March 11, 2010, 08:32:10 AM »
Thanks. Coulnd't find geoip for free, but found a way to redirect simply by htaccess;

Code: [Select]
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 ;)

Offline XeNoMoRpH1030

  • Enthusiast
  • Posts: 71
    • View Profile
    • Blue Line Attack
Re: How to automatically redirect users according to their ip?
« Reply #3 on: March 11, 2010, 09:33:02 AM »
There are plenty of free APIs out there.

You can do grab
Code: [Select]
http://api.hostip.info/get_html.php?ip=12.215.42.19 with PHP and it will return something like this
Code: [Select]
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.

Offline vinnierTopic starter

  • Enthusiast
  • Posts: 56
    • View Profile
Re: How to automatically redirect users according to their ip?
« Reply #4 on: March 11, 2010, 08:00:25 PM »
Thanks but all of this is confusing me...  :wtf: 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?

Offline teamatomic

  • Devotee
  • Posts: 1,197
  • Gender: Male
  • fat skis rule!
    • View Profile
    • myPHPtemplate
Re: How to automatically redirect users according to their ip?
« Reply #5 on: March 12, 2010, 12:14:18 AM »
This is the free geoIP csv file

http://www.maxmind.com/app/geolitecountry



HTH
Teamatomic
when in doubt...ski fast
when scared...ski faster
when terrified...point em down