473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

what to do if user forgot to log out?

Hello.

I have a question about handling special cases of session expiration.
In a project I'm working on, the users must log out or else their
profile will be left in an unusable state -- at least until the
administrator fixes it by hand.

What is the proper way of handling this? Is there a way to supply a
function that is called when a session times out? What if the browser
is closed?

I realize the best solution might depend on many things, so I'll be
grateful for any pointers.

Thanks,

andrej

Jul 17 '05 #1
6 1978
sp*****@volja.net wrote:
I have a question about handling special cases of session expiration.
In a project I'm working on, the users must log out or else their
profile will be left in an unusable state -- at least until the
administrator fixes it by hand.


IMO, this is the same as a user logging in and doing absolutely nothing
until the session expires.

How does your application handle that?
JW

Jul 17 '05 #2
>I have a question about handling special cases of session expiration.
In a project I'm working on, the users must log out or else their
profile will be left in an unusable state -- at least until the
administrator fixes it by hand.
This kind of design you should avoid at all costs. The administrator
may either go insane or may be convicted for murdering you.

If you must enforce logging in only once, when duplicate logins
happen, kick off the *OLD* login.
What is the proper way of handling this? Is there a way to supply a
function that is called when a session times out? What if the browser
is closed?
It is common to have a session expire after some timeout after the
last hit or after login. It is *NOT* common to have code run at
that time. If your design requires that, well, do it another way.
It is common to check if the login has expired (might be days after
the session has expired) on each hit, and if so, redirect to the
login page again.
I realize the best solution might depend on many things, so I'll be
grateful for any pointers.


Users can have their sessions end for numerous reasons and they
cannot clean up afterwards: the computer crashes. Their dialup
line drops and they get back a different IP on redialing. Power
failures. The browser crashes. So forget about having code run
when any of these happen. You can have code run when they attempt
using the same session *after* it has expired (possibly years later).

Gordon L. Burditt
Jul 17 '05 #3
One reason to want to have something run on logout/session time out is
to keep track of online/offline users (many bulletin boards have to
deal with this problem).

One solution is to have a function call at the beginning of each page
that checks if it has been 5 minutes (or whatever time you want) since
the last action of all users. You keep track of all users yourself
through database entries or something similar and if some of them
appear inactive, you clean them up.

This can has a negative impact on performance as you are running a lot
of code that in most cases will do nothing, but it should work ok in
most circumstances. It also has the side-effect that if your site in
general is not very popular, the clean up may happen hours later, when
the next visitor comes to see a page. This second disadvantage is
addressed below.

Another solution is to have a cron job, that is separate from your
application and runs every n minutes to check for similarly setup
database or other user tracking mechanism and clean up inactive
entries.

Anyone else? I am actually trying to think of a better way to do this
as neither of the above works perfectly (as in optimized from an
algorithmical point of view) and I would appreciate to hear if someone
has figured out a better approach.

Jul 17 '05 #4
Following on from 's message. . .
Hello.

I have a question about handling special cases of session expiration.
In a project I'm working on, the users must log out or else their
profile will be left in an unusable state -- at least until the
administrator fixes it by hand.

What is the proper way of handling this? Is there a way to supply a
function that is called when a session times out? What if the browser
is closed?
Go back to programming school!

"Unstable states" are no more acceptable in software than loose bolts
holding aeroplane wings on.


I realize the best solution might depend on many things, so I'll be
grateful for any pointers.

Thanks,

andrej


--
PETER FOX Not the same since the pancake business flopped
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Jul 17 '05 #5
cyberhorse said the following on 12/06/2005 08:51:
One reason to want to have something run on logout/session time out is
to keep track of online/offline users (many bulletin boards have to
deal with this problem).

One solution is to have a function call at the beginning of each page
that checks if it has been 5 minutes (or whatever time you want) since
the last action of all users. You keep track of all users yourself
through database entries or something similar and if some of them
appear inactive, you clean them up.

This can has a negative impact on performance as you are running a lot
of code that in most cases will do nothing
It shouldn't have that much of an effect if you push the clean-up into
the database query, i.e. you do something like:

UPDATE users SET online = 0 WHERE (lastOnlineTime + x) < NOW()

Although I haven't tested the speed of this, so I could be wrong! It's
almost certainly faster than doing it in manually in PHP though. (You
could probably optimise this by adding "online = 1 AND" into the WHERE
clause, and indexing the online column... maybe)
It also has the side-effect that if your site in
general is not very popular, the clean up may happen hours later, when
the next visitor comes to see a page. This second disadvantage is
addressed below.


Is this one really a disadvantage though? You're right, the clear-up
won't happen for hours, but there's no-one using the site in the interim
to find this out!!

The update still occurs exactly when it needs to, i.e. just before a
user uses the site/page.
--
Oli
Jul 17 '05 #6
Oli Filth wrote:
cyberhorse said the following on 12/06/2005 08:51:
One reason to want to have something run on logout/session time out is
to keep track of online/offline users (many bulletin boards have to
deal with this problem).

One solution is to have a function call at the beginning of each page
that checks if it has been 5 minutes (or whatever time you want) since
the last action of all users. You keep track of all users yourself
through database entries or something similar and if some of them
appear inactive, you clean them up.

This can has a negative impact on performance as you are running a lot
of code that in most cases will do nothing


It shouldn't have that much of an effect if you push the clean-up into
the database query, i.e. you do something like:

UPDATE users SET online = 0 WHERE (lastOnlineTime + x) < NOW()

Although I haven't tested the speed of this, so I could be wrong! It's
almost certainly faster than doing it in manually in PHP though. (You
could probably optimise this by adding "online = 1 AND" into the WHERE
clause, and indexing the online column... maybe)


The speed problem can be cleared up if you use a column "sessionExpireTime",
and then index on sessionExpireTime, and then query like so:

UPDATE sessions SET online = 0
WHERE sessionExpireTime < NOW()
AND session <> session_id

....while this may seem like nitpicking, it ensures that the server will
always use the index, regardless of which server platform you are using.

It is also important to filter out the session you are working with, because
in a moment you are about to issue this query to refresh the current
session:
UPDATE sessions set sessionExpireTime = NOW() + x
WHERE sessionid = session_id

....and on a busy site the processes doing the first update will keep
deadlocking with the processes doing the second update and your site will
lock up.

--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rachel Suddeth | last post by:
What is the difference between a managed/unmanaged resource, and how do you tell which is which? I'm trying to understand how to write some Dispose() methods, and we are supposed to put code that...
15
by: Edwin Knoppert | last post by:
I have searched but info is limitted. In my test app i used a non persistant cookie for forms authentication. slidingExpiration is set to true On run and close and rerun the login remains ok....
0
by: kuldeep singh sethi | last post by:
Hi All I want to know that when any user forgot the password as yahoo mail, then a button which is said to click on that to know password. so i want to know that code in C# that how...
1
by: kuldeep singh sethi | last post by:
Hi All I want to know that when any user forgot the password as yahoo mail, then a button which is said to click on that to know password. so i want to know that code in C# that how to send mail...
3
by: bb nicole | last post by:
I have did the company login and job post which means that company can post the job after they login in my webpage.. I had set company_ID(tablename:company) is foreign key of table job. But when i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.