0

Coldfusion has a system created client variable called lastvisit.

Is there a way to get the value of that variable during the request that it is actually set (i.e. client.thisvisit)?

The idea would be that I can store the "ThisVisit" timestamp in session and then compare it to lastvisit when the next request is made. This would tell me if another request was made in the session.

The purpose is that we have a page that we use an ajax record lock on which refreshes the lock every minute. After sixty minutes the ajax lock code will automatically log the user out of the website (due to inactivity). The issue arises where the user is executing tasks in other windows/tabs (indication of activity).

Sense all requests update LastVisit, I would like to have the ajax lock code save the save a "thisvisit" value so that the next time it runs it can compare it to the LastVisit client variable.

5
  • What's wrong with <cfset Request.ThisVisit = Now() /> inside of onRequestStart? (along with subsequent session checks/storage) Jun 11, 2012 at 11:46
  • @PeterBoughton I'm guessing that they won't necessarily be equal. However, you are right that I could also set up my own "lastvisit" in the same way. Jun 11, 2012 at 11:48
  • Well, I suppose depends if the client variable is set at the start or the end of the request, but could use onRequestEnd too, and I wouldn't expect more than a couple of milliseconds difference either way. It'd probably be better to do a LT/GT check rather than direct equality, if you're testing whether the current is the newest request? Jun 11, 2012 at 11:53
  • (I may be missing the point entirely - might help to add more details of what the intended use is for this to the question?) Jun 11, 2012 at 11:55
  • 1
    I usually recommend against enabling the "global" variables in the client tables. You are better off simply creating a timestamp in the session with your first request and then checking for it updating and diffing it with subsequent requests. If you still need to know I'll add an answer for you :) Jun 11, 2012 at 13:20

1 Answer 1

2

A couple requirements:

  • Set up to use a DB rather than registry for your client vars (trust me).
  • Client vars have to have "global variables" enabled
  • Your cfapplication or application.cfc has to have client management enabled.

If you have those three things you can select a query like the following:

<cfquery name="getLvisit" datasource="myClientVarsDB">
    SELECT lvist 
    FROM   cglobal
    WHERE  cfid = 
        <cfqueryparam type="CF_SQL_CHAR" value="#urltoken#"/>
</cfquery>

urltoken might be wrong... it may need the jsessionID or CFID but my memory tells me cftoken. I'd have to hunt down a site using Client DBs to give you a definitive answer.

So that would give you the current value of the lvisit variable. you would store this in the session and then compare it against the value from the table on subsequent queries before you overwrite it again (if that makes sense).

Note - this value is updated on each request - so your query get's the current value (before it has been updated). I previously thought this it was updated first but according to Tom it's actually updated last.

3
  • Thanks. According to tests and the sql logs, the value does not get updated until after the processing of the page. I made a page that sleeps for ten seconds and the lvisit value is at the end of that period. This effectively answers my question with a NO. Jun 11, 2012 at 14:29
  • ok.. I'll edit my post to reflect that. Again - this would be more trouble than simply tracking it in the session. Jun 11, 2012 at 14:32
  • Yes, at this point it is much more trouble. If there was a simple ThisVisit var, I could do all management from the ajax code without having to modify the other applications involved. Jun 11, 2012 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.