There is a code that shows a message to a specific IP address: if ($_SERVER['REMOTE_ADDR'] == '93.184.216.34') die('Доступ запрещён!'); How to make it possible to add multiple IP addresses or address ranges at once as type 192.168.0.0/16

  • Also note that $ _SERVER ['REMOTE_ADDR'] does not always give the real client ip. - Alexander Semikashev

1 answer 1

Show message to multiple users:

 $userIP = $_SERVER['REMOTE_ADDR']; $ips = ['1.1.1.1', '1.1.1.2', '1.1.1.3']; if (in_array($userIP, $ips)) { exit('hello'); } 

For the second option, I advise you to use some kind of ready-made library, since the standard library of functions does not contain such functionality.

For example, I took this one - https://github.com/wikimedia/ipset

 $userIP = $_SERVER['REMOTE_ADDR']; $cidr = '10.64.0.0/22'; $ipset = new Wikimedia\IPSet([ $cidr, ]); if ($ipset->match($userIP)) { exit('hello'); } 
  • So, with the second option, where are the ranges, how can you add more ranges as in option one? - Helpsetup
  • Then how to connect Wikimedia \ IPSet and where to download? - Helpsetup
  • Download here github.com/wikimedia/IPSet/releases And how to connect? - Helpsetup
  • 1) The constructor of the IPSet class accepts an array of ranges. 2) You can connect the library through Composer: packagist.org/packages/wikimedia/ip-set - Egor Smolyakov
  • My website in html itself wrote and php supports. I know how to connect the JS library, but with this I do not catch up with something? Give an example please? - Helpsetup