Handling Session timeout


I wanted to discuss an issue related to session logout in yii, which i feel is a common problem in many apps.

I am using CJuiTabs in my application that displays Ajax Content after the user logs into the system. The issue is that in-case the user logs out from the application from some other window or his session times out, and then clicks one of the tabs, at first instant the whole index layout is rendered as the view in the tab content area and then certainly the screen goes white, which shouldn’t happen, the user must see login screen or should be redirected to login page in case his session has timed-out.

I looked around and found some solutions here http://danaluther.blogspot.com/2010/04/loginrequired-and-ajax-updates.html

But,the thing is that suppose you logout from one window, click at tab, you see the session timeout error, however, if you login again, the tabs view is rendered distorting site layout.

Is there a way to overcome this issue? Please suggest!



OK, I solved the issue by using above url like this:

class WebUser extends CWebUser


public function loginRequired()


   $app = Yii::app();

   $request = $app->getRequest();


   $this->setReturnUrl( $request->getUrl() );


   if ( $request->isAjaxRequest )



      echo "<script>alert('you need to login to perform this action!');window.location.reload();</script>";

   } else {

      if ( ($url = $this->loginUrl) !== null )


          if (is_array($url))


              $route=isset($url[0]) ? $url[0] : $app->defaultController;






        throw new CHttpException(403, Yii::t('yii', 'Login Required'));