Hi everyone, this is my first forum post. I’ve started using yii a few months ago and I am loving it!
I thought I’d make my contribution, perhaps someone is struggling with the same issue.
In my application I have a number of javascript functions that open dialogs and such.
Naturally, if the user’s session has expired I wish to prevent him to do so, and redirect him to the login page.
This may seem rather crude but my solution is the following:
My javascript function (makes an AJAX call to controller):
checkSession = function(){
$.get(baseUrl + '/site/ajaxCheckSession','', function(data_in) {
if (data_in != ''){
// Redirect user with passed location
window.location = data_in;
}
});
}
The AJAX function in the controller:
public function actionAjaxCheckSession() {
// Create sessions object
$sessions = new CHttpSession();
// run getSessionId, this seems to trigger garbage collection...
$sessions->getSessionId();
if (count($_SESSION) == 0){
// No session? pass location redirect to javascript!
echo $myUrl;
}
}
And there you go…
Hope that is useful to someone!