Topic: Session check for all requests
Hi all,
the user BigBadaBoom wrote a nice example for checking session on each request. Here's a short summary:
You certainly know that $xajax->register() supports different 'types' of functions... like XAJAX_FUNCTION, XAJAX_CALLABLE_OBJECT and so on... There's also one magic constant for registering Events "XAJAX_PROCESSING_EVENT". In combination with XAJAX_PROCESSING_EVENT_BEFORE, xajax will always call a certain (xajax) function before it processes the requested function(s). This way, you can add a session check before the real processing starts and abort the further processing if needed (for instance when the session is invalid).
Code: PHP
$xajax->register(XAJAX_PROCESSING_EVENT, XAJAX_PROCESSING_EVENT_BEFORE, "loginstatus");
// the function which is called before processing
function loginstatus(&$callnext)
{
// Check if session is valid or not
if (!$GLOBALS['user']->isLoggedIn())
{
// If the session is not valid, set callnext to false in order to skip the further request processing
$callnext = array(false);
// create a new xajaxResponse(); object and redirect the user to the login page
$objResponse = new xajaxResponse();
$objResponse->loadCommands(myLogoutFunction());
// Return the response object with instructions
return $objResponse;
}
}