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); }