3
我想限制只有一个IP(或IP列表)的控制器的访问。Yii2 - 通过IP验证AccessControl
什么是正确的配置方式? (例如,我只希望IP 172.19.37.175
有权访问index.php?r=painel/restrict
)。
我试着这样说:
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::classname(),
'only' => ['index'],
'rules' => [
[
'allow' => true,
'roles' => ['?'],
'ips' => ['172.19.37.175'],
],
],
'denyCallback' => function ($rule, $action) {
throw new \Exception('You are not allowed to access this page');
}
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
你的代码..似乎是正确的..什么是你的问题..你有错误? worng结果? – scaisEdge
当试图访问我的IP 172.19.37.175时,它显示:您不能访问此页访问索引 – gugoan
?的index.php?R =索引? – scaisEdge