-1

I have a website made with php which has a login page. Is there any way to block access to ip address from other countries to login? I mean user from another countries will be able to visit the website but not login. If anyone tries to login, his ip will be blocked. Is there any way to achieve this in php?

  • Do you have access to the credential database for this site? Can you just prevent people in these countries from creating logins in the first place? – Russ J Feb 22 '19 at 13:42
  • 1
    Which part are you stuck on? What have you tried and what isn't working? – David Feb 22 '19 at 13:42
  • `print_r($_SERVER)`. you can see the requested details param.Validate some param as your need – prasanth Feb 22 '19 at 13:43

2 Answers2

1

PHP has a 'geoip_country_name_by_name()' that might help you here. It accepts IP addresses as parameters if you can get that info.

http://php.net/manual/en/function.geoip-country-name-by-name.php

Russ J
  • 828
  • 5
  • 12
  • 24
  • Genereally, what I want is to check the ip address of the users pc when he tries to login and which country it belongs to @Russ J – user10903858 Feb 22 '19 at 13:50
  • 1
    Note that `geoip_country_name_name` require `geoip` PECL extension to be installed, which is generally not by default. – Clément Baconnier Feb 22 '19 at 13:51
  • Getting the IP is easy enough as well https://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php – Russ J Feb 22 '19 at 13:59
0

If you need something more specific or granular you may have to integrate with a provider like https://ipstack.com/. There you can get the granular information. They are hundreds of geoip companies that provide the info, you can get access to a database and imported to your site, but this ip ranges can change on a daily basis and that's why we have so many providers because people really needs accurate info.

Vidal
  • 2,605
  • 2
  • 16
  • 32