<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[xajax Forums - Session check for all requests]]></title>
	<link rel="self" href="http://community.xajaxproject.org/feed/atom/topic/6944/"/>
	<updated>2009-07-02T19:01:58Z</updated>
	<generator>PunBB</generator>
	<id>http://community.xajaxproject.org/topic/6944/session-check-for-all-requests/</id>
		<entry>
			<title type="html"><![CDATA[Re: Session check for all requests]]></title>
			<link rel="alternate" href="http://community.xajaxproject.org/post/28334/#p28334"/>
			<content type="html"><![CDATA[Hi q_no,

I tried this and works great for me, except that I had to move the return on the loginstatus function outside the "if", otherwise I kept getting [i]<cmd cmd="dbg">SAn invalid response was returned while processing this request.</cmd>[/i].  Always returning the xajaxResponse object works well for me.  I added the [i]myLogoutFunction[/i] implementation, it might help someone else saving some extra time checking the docs for the loadCommands method, cheers.

[code]
function myLogoutFunction() {
  $objResponse = new xajaxResponse();
  $sURL = Configuration::APP_URL."/login.php?logout=1";
  $objResponse->redirect($sURL);
  return $objResponse;
}

// the function which is called before processing
function loginstatus(&$callnext) {
// create a new xajaxResponse(); object and redirect the user to the login page
  $objResponse = new xajaxResponse();
  
  // 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);
    
    $objResponse->loadCommands(myLogoutFunction());
  }
  // Return the response object with instructions
  return $objResponse;
}[/code]

-- 
I'm using xajax 0.5 final]]></content>
			<author>
				<name><![CDATA[bdevelopment]]></name>
				<uri>http://community.xajaxproject.org/user/4008/</uri>
			</author>
			<updated>2009-07-02T19:01:58Z</updated>
			<id>http://community.xajaxproject.org/post/28334/#p28334</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Session check for all requests]]></title>
			<link rel="alternate" href="http://community.xajaxproject.org/post/25657/#p25657"/>
			<content type="html"><![CDATA[Hi all,

the user BigBadaBoom wrote a [url=http://community.xajaxproject.org/viewtopic.php?pid=25614#p25614]nice example[/url] 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]// register the function "loginstatus" as PROCESSING_EVENT before the real processing starts
$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;
       }
}[/code]]]></content>
			<author>
				<name><![CDATA[q_no]]></name>
				<uri>http://community.xajaxproject.org/user/569/</uri>
			</author>
			<updated>2008-09-09T13:29:24Z</updated>
			<id>http://community.xajaxproject.org/post/25657/#p25657</id>
		</entry>
</feed>
