Block specific IP block from my website in PHP

前端 未结 8 1516
小蘑菇
小蘑菇 2020-12-05 12:02

I\'d like, for example, block every IP from base 89.95 (89.95..). I don\'t have .htaccess files on my server, so I\'ll have to do it with PHP.

8条回答
  •  悲哀的现实
    2020-12-05 12:26

    Convert the dotted quad to an integer:

    $ip = sprintf('%u', ip2long($_SERVER['REMOTE_ADDR']));
    
    // only allow 10.0.0.0 – 10.255.255.255
    if (!($ip >= 167772160 && $ip <=  184549375)) {
        die('Forbidden.');
    }
    

提交回复
热议问题