I'm using Yii 1.1.16, and am trying to add an accessRules to filter by IP
This is my code in my CommentsController. It still allows my localhost IP to access the action. Other than my actions, this is the only other function in my controller.
What am i missing or doing wrong? Thanks
public function accessRules() {
return array (
array ('allow', // allow all users to perform these actions
'actions' => array ( 'Comments' ),
'ips' => array(
/*"127.0.0.1",*/ /* localhost */
/*"::1",*/ /* localhost */
"52.XX.XX.XX" //live site
)
),
);
}
You'll have to add a deny too:
......
public function filters()
{
return array(
'accessControl', //access control filter should be applied to every action of the controller
);
}
public function accessRules() {
return array (
array ('allow', // allow all users to perform these actions
'actions' => array ( 'comments' ),
'ips' => array("52.XX.XX.XX")
),
array ('deny', //deny by default
'ips' => array("*")
),
);
}
The reason for having a deny rule is because if none of the rules matches a context, then the deny rule gets executed. More info here.
You can try following code.
//controller file.
public function filters()
{
return array( 'accessControl' ); // perform access control for CRUD operations
}
public function accessRules() {
return array (
array ('allow', // allow all users to perform these actions
'actions' => array ( 'Comments' ),
'ips' => array(
"52.XX.XX.XX" //live site
)
),
array ('deny', // deny all users to perform these actions
'actions' => array ( 'Comments' ),
'ips' => array('*')
),
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With