Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Run command on session ends

  1. #1
    Join Date
    Sep 2004
    Posts
    356
    Rep Power
    0

    Unhappy Run command on session ends

    hey I am using Dream weaver I was wondering how to run a certain command like a update query on session ends because these user's dont like to logout properly so when the close the window I want a command to run to change the user status to "OFFLINE" oh yeah I dont want to use any pop up window

    I am open to suggestions
    oh yeah dont want to use application text either

  2. #2
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default Re: Run command on session ends

    First thing that comes to mind is using the global.asa file and in the subroutine Session_OnEnd you can put your query.

    Second thing is to call a javascript function when the browser closes that will open a small window and execute your query.

    Third thing that comes to mind is in your script, you have a query that is executed each time a persons visits your webpages, and check to see if a user is still active on your site by comparing the last time they accessed a page, and the current time. If say after 5 minutes they have not accessed a page, you can set them offline.
    But this requires your site to be fairly active.
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  3. #3
    Join Date
    Sep 2004
    Posts
    356
    Rep Power
    0

    Default Re: Run command on session ends

    Arch I know what you where gonna tell me before you even start ok Global.asa good Idea but you see where the pop is concern some of the user's use POP up blocker so if the page is blocked they wont be logged out so I need an alternative do you think the globla.asa will cover it up without the pop up

  4. #4
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default Re: Run command on session ends

    Yes, the global.asa would work. Just that the session times out by default after 20 minutes on IIS. You can change this using code:
    Code:
    Session.Timeout = 5
    That would change it to 5 minutes. That way your update query in global.asa would run after 5 minutes on inactivity fromthe user.

    I see your point about the popup-blockers. I guess it wouldn't work here then.
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  5. #5
    Join Date
    Sep 2004
    Posts
    356
    Rep Power
    0

    Default Re: Run command on session ends

    I guess your right I was thinking about making the session timeout a bit shorter then again if I take 5 mins to read a post what happens then?

    Next issue is this when the user close the page would it run the query in the global.asa I dont really use this file that much as one person put it (Gloaba.asa is white elephant of ASP most people dont even know it exist)

  6. #6
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default Re: Run command on session ends

    I wouldn't make it so short either. 10-15 minutes is good. This forum times-out users after 20 minutes of inactivity.

    The only way to run any kind of code when a user closes thier browser is using javascript, and having the code onUnload="some_function()" in the body tag of the page. That's the only way to detect when a user closes thier browser.

    Since we can't run an sql query via javascript, it won't work.

    The code in global.asa will only run when the users session times out. Which is, as said before, 20 minutes by default or you can change it in your script.
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  7. #7
    Join Date
    Sep 2004
    Posts
    356
    Rep Power
    0

    Default Re: Run command on session ends

    Arch you still not getting what I am saying I am asking if the user close the page will the global.asa run the code for me because when the user close the window that ends there session automatically

  8. #8
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default Re: Run command on session ends

    I understand you completely. I was explaining to you the process of when the global.asa code executes and what happens when the browser window closes.

    The short answer to your question is: no.
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  9. #9
    Join Date
    Sep 2004
    Posts
    356
    Rep Power
    0

    Default Re: Run command on session ends

    ok I have an Idea could javascript code to redirect you when the user unload the page

  10. #10
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default Re: Run command on session ends

    I don't think it can, because the browser window is closed, it can't display a new webpage without opening a new window.
    You can try it, but I doubt it will work.

    Thing is, there is no way to know if the user left a site, when they close the browser. Unless you do the open window way with javascript.

    So the most you can do is log them off after a few minutes of inactivity.
    Or have a function that constantly checks if the user is on the site.
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •