You are viewing revision #1 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.
In some cases, we have to limit the number of page views for the guests users. Yii provide an efficient method to get this.
Here is how you can do this, if your application requires this.
Open file
protected/components/Controller.php
and add the following code there in
public function beforeAction($action) {
// allowed actions to be performed
$allowed=array(
'login','register','passwordreset','updatepassword','logout'
);
// page views
if(!isset(Yii::app()->session['pages'])){
Yii::app()->session['pages']=1;
}else{
Yii::app()->session['pages']=Yii::app()->session['pages']+1;
}
$pages = Yii::app()->session['pages'];
if(Yii::app()->user->isGuest){
if($pages>10){
if(!in_array($action->id, $allowed)){
$this->redirect(array('/member/login')); // redirect to login
}
}
}
return parent::beforeAction($action);
}
question
And what's up when i disable cookies? :-)
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.