假设我具有以下要阻止的 IP 范围 89.96.53.158和89.96.53.189
这是如何尝试实现它。
我的问题:按照下面的代码,这是最好的方法吗?下面的代码是否正确
UPDATE `myTable`
INNER JOIN JSON_TABLE(
`myTable`.`data`,
'$[*]'
COLUMNS(
`position` FOR ORDINALITY,
`ID` INT PATH '$.ID'
)
) `der`
SET `data` = JSON_REPLACE(
`myTable`.`data`,
CONCAT('$[', `der`.`position` - 1, '].OD'),
'3/1'
)
WHERE `der`.`ID` = 63010092;
我还可以使用$ip = sprintf('%u', ip2long($_SERVER['REMOTE_ADDR']));
$start_ip = sprintf('%u', ip2long("89.96.53.158"));
$end_ip = sprintf('%u', ip2long("89.96.53.189"));
// stop only ip range between 89.96.53.158 - 89.96.53.189
if ($ip >= $start_ip && $ip <= $end_ip) {
echo "you cannot access our site";
exit();
}
函数来实现这一点
答案 0 :(得分:0)
是的,我想出了另一种使用 strpos()方法的方法
if(strpos($_SERVER['REMOTE_ADDR'], "89.96") === 0)
{
echo "you cannot access our site";
exit();
}
如果您注意到,===
运算符将确保89.96位于 IP地址的开头。
这意味着您可以根据需要指定任意数量的 IP 地址,无论后面紧跟什么数字,它都会阻止。