Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asptoday_discuss thread: Session Variables


Message #1 by "Patrick Ames" <patrick00@n...> on Mon, 19 Nov 2001 20:52:59
Hi there

on my site users logging in are added to a database and a field called 

logged in is given a value of 1. This is so i can see who is online and 

who is not. The user is assigned a session during the duration of their 

stay on the site. My problem being, If they use the log out button then a 

value of 0 is written to the database. Humans being Humans though rarely 

use the log out button which causes a problem. 

Is there a way that if a user either leaves the site by changing the http 

address or by closing the browser, that we can force a write to the 

database to assignt eh value of 0 to the field when they leave?



Thanks

Patrick
Message #2 by "Scott Reed" <scottr@m...> on Mon, 19 Nov 2001 16:25:16 -0600
Patrick,



I don't already know the answer to your question but I suspect the problem

could be solved by

one of the two following methods;



1)Use a timer to check the session/userID. When a user logs in, it starts a

timed routine. When the

UserID value = "", it sets db field to 0 and ends.



  if Session("UserID") = "" then

'-------------------------------

' User is not logged in, set db field to 0, else record = 1

'-------------------------------



2) Add a check to a global include file so that the session/userID is check

with every page.

Each time a page is loaded or reloaded it will confirm their logged-in

status. After a period of

time (time-out) have a routine set it to 0 (default).



Have no idea if this will help, hope it does...



Scott Reed

Media Cybernetics Technical Services





-----Original Message-----

From: Patrick Ames [mailto:patrick00@n...]

Sent: Monday, November 19, 2001 8:53 PM

To: ASPToday Discuss

Subject: [asptoday_discuss] Session Variables





Hi there

on my site users logging in are added to a database and a field called

logged in is given a value of 1. This is so i can see who is online and

who is not. The user is assigned a session during the duration of their

stay on the site. My problem being, If they use the log out button then a

value of 0 is written to the database. Humans being Humans though rarely

use the log out button which causes a problem.

Is there a way that if a user either leaves the site by changing the http

address or by closing the browser, that we can force a write to the

database to assignt eh value of 0 to the field when they leave?



Thanks

Patrick




$subst('Email.Unsub')



Message #3 by "Jason Salas" <jason@k...> on Tue, 20 Nov 2001 08:40:54 +1000
You could try shortening the session's timeout value....and write something

within the script to check what the value is and evaluate it (like a Boolean

value, which fits perfectly with what you're doing with a value of 1 or 0).



Something like:



Dim blnConnectionsIsAlive, session

blnConnectionIsAlive = True    ' default value

Session.Timeout = 3    ' the session expires in 3 minutes

automatically...the default value is 10...as long as you're not persisting

any major information like credit cards, shopping cart data, this should be

OK

If Session("user") = " " Then    ' user does not have a session and is thus

not logged on to your site

blnConnectionIsAlive = False    ' user must have clicked out of the site

Session.Abandon

...write the value to the DB here..........

End If





The only problem here is that the script can't execute if the user's already

gone.  :(



But maybe something to think about.





----- Original Message -----

From: "Patrick Ames" <patrick00@n...>

To: "ASPToday Discuss" <asptoday_discuss@p...>

Sent: Monday, November 19, 2001 8:52 PM

Subject: [asptoday_discuss] Session Variables





> Hi there

> on my site users logging in are added to a database and a field called

> logged in is given a value of 1. This is so i can see who is online and

> who is not. The user is assigned a session during the duration of their

> stay on the site. My problem being, If they use the log out button then a

> value of 0 is written to the database. Humans being Humans though rarely

> use the log out button which causes a problem.

> Is there a way that if a user either leaves the site by changing the http

> address or by closing the browser, that we can force a write to the

> database to assignt eh value of 0 to the field when they leave?

>

> Thanks

> Patrick



Message #4 by "Greg Jennings" <greg.jennings@t...> on Wed, 28 Nov 2001 16:38:51
Since ASP scripts execute before the page is sent to the user, there is 

not a way for ASP code to determine when a user leaves your site.  

However, you should be able to use a client-side script that executes when 

the browser window is closed.  This script could send the user to a 

particular page on your site, say Logout.asp, with the session ID as a 

parameter.  The Logout.asp could log out the user in the database.
Message #5 by "Jason Salas" <jason@k...> on Thu, 29 Nov 2001 08:04:01 +1000
Well technically, a session variable will "end" when any of the following

occur:



 - the session object's TIMEOUT property is exceeded (i.e., Session.Timeout

= 30)

 - the ABANDON method of the session object is called (i.e.,

Session.Abandon)

 - a user clicks out of your site

 - other specified events



You can manipulate these factors to some extent...but I agree...in general,

using the "Log Me Out" feature is best for brevity and reliability.



Jason



----- Original Message -----

From: "Greg Jennings" <greg.jennings@t...>

To: "ASPToday Discuss" <asptoday_discuss@p...>

Sent: Wednesday, November 28, 2001 4:38 PM

Subject: [asptoday_discuss] Re: Session Variables





> Since ASP scripts execute before the page is sent to the user, there is

> not a way for ASP code to determine when a user leaves your site.

> However, you should be able to use a client-side script that executes when

> the browser window is closed.  This script could send the user to a

> particular page on your site, say Logout.asp, with the session ID as a

> parameter.  The Logout.asp could log out the user in the database.




$subst('Email.Unsub')

> Read the future with ebooks at B&N

>

http://service.bfast.com/bfast/click?bfmid=2181&sourceid=38934667&categoryid

=rn_ebooks

>




  Return to Index