Web Connection
Error in wwSession
Gravatar is a globally recognized avatar based on your email address. Error in wwSession
  Yonggu
  All
  Mar 14, 2019 @ 07:36pm

Hi! Rick.

I think there are some bugs in wwSession.

************************************************************************
* wwSession :: LocateSession
*********************************
***  Function: Loads the oData member with the session data. 
***            This is a low level function that you typically
***            won't address directly. Use IsValidSession instead.
***      Pass: lcSessionID  -  Session to load (or reload current)
***            llIgnoreTimeo - retrieves a session entry even
***                            if it's expired
************************************************************************
FUNCTION LocateSession
LPARAMETERS lcSessionId, llIgnoreTimeout
LOCAL llResult

lcSessionId=IIF(type("lcSessionId")="C",lcSessionId,THIS.cSessionId)

THIS.cSessionid = ""
IF EMPTY(lcSessionId)
   RETURN .F.
ENDIF   

THIS.OpenTable()

** Force table buffers to refresh!!!
** Necessary for high volume applications so that sessions
** created in one request can immediately be seen by others
** such as scripts or other iframes/ajax calls
REPLACE SessionId with SessionId  

lcLocateId = lcSessionId 

llResult = .F.

IF !llIgnoreTimeout
	LOCATE FOR SessionId == lcLocateId AND ;
		       LastOn >  DATETIME() - THIS.nSessionTimeout 	    
	IF FOUND() 
	   SCATTER NAME THIS.oData MEMO
	   THIS.cSessionId=wwSession.SessionId
	   this.oData.LastOn = DATETIME()  && Rolling expiration
	   RETURN .T.
	ENDIF

	SCATTER NAME THIS.oData MEMO BLANK
    THIS.cSessionId=""
ELSE
    SELECT TOP 1 * FROM wwSession ;
    	WHERE SessionId == lcLocateId ;
    	ORDER BY LastOn DESC ;
    	INTO CURSOR __TSession
    	
    IF _tally > 0
       SCATTER NAME THIS.oData MEMO
	   *THIS.cSessionId=wwSession.SessionId
           THIS.cSessionId=__TSession.SessionId
	   this.oData.LastOn = DATETIME()	   
	   llResult = .T.
	ELSE
       SCATTER NAME THIS.oData MEMO BLANK
    ENDIF
    
    USE IN __TSession	
    SELECT wwSession
ENDIF

RETURN llResult
ENDFUNC
* LocateSession


FUNCTION IsValidSession
************************************************************************
* wwSession :: IsValidSession
*********************************
***  Function: Locates the record pointer on the specific session.
***            If found and not timed out the  is updated.
***      Pass: lcSessionID  -   A session ID (typically stored in Cookie)
***            llIgnoreTimeout - Ignores timeout
***    Return: .T. if found, .F. if not found
************************************************************************
LPARAMETERS lcSessionId, llIgnoreTimeout

*** Check for existance and timeout
IF THIS.LocateSession(lcSessionId, llIgnoreTimeout)
   THIS.oData.LastOn = DATETIME()
   *THIS.oData.Hits = Hits + 1
   THIS.oData.Hits = THIS.oData.Hits + 1
   THIS.cSessionId= THIS.oData.SessionId
   RETURN .T.
ENDIF

THIS.cSessionId=""
RETURN .F.
ENDFUNC
* IsValidSession 

Yonggu

Gravatar is a globally recognized avatar based on your email address. re: Error in wwSession
  Rick Strahl
  Yonnggu
  Mar 15, 2019 @ 10:03pm

That's not helpful...

What is not working?

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Error in wwSession
  Yonggu
  Rick Strahl
  Mar 18, 2019 @ 05:19am

I am sorry for my belated reply.
And, I am sorry that I didn't explain what was not working in detail.

I am a Korean so that I am not good at English.
So, It's not certain for me to make you understand what I want to say.

Anyway, I am going to try it.

The purpose of LocateSession() is to find a record by lcSessionId given parameter. If found(), it sets THIS.cSessionId to wwSession.SessionId and THIS.oData.LastOn to DATETIME().

In case llIgnoreTimeout, the code in wwSession execute a query to find a record and If found(), it sets THIS.cSessionId to wwSession.SessionId and THIS.oData.LastOn to DATETIME().

Since using a query, I think that THIS.cSessionId is set with __TSession.SessionId, not wwSession.SessionId.

In IsValidSession(), if THIS.LocateSession() is success, it set THIS.oData.Hits to Hits + 1.

This is not working because of Hits + 1.

Using a query, the value is wwSession.Hits.

So, I think THIS.oData.Hits is set with THIS.oData.Hits + 1.

Do you understand what I want to say?

© 1996-2024