Welcome Guest!

If you do not have an account yet on The Web Squeeze forums, please Register! It’s FREE and there are many benefits:

  • Receive Fast Advice
  • Learn Programming Languages
  • Get Professional Website Reviews
  • Quick Troubleshooting Assistance

> Logoff When Session Ended

This is a discussion on Logoff When Session Ended, within the ASP/.NET section. This forum and the thread "Logoff When Session Ended" are both part of the Programming Your Website category.

 
Reply to this topicStart new topic
> Logoff When Session Ended
Monie
post May 26 2008, 12:23 AM
Post #1


Squeeze Machine
*****

Posts: 732
Joined: 13-February 08
From: Borneo


I have a script on top of my protected page which will redirect the user to a certain page if the session has ended!
The problem is, upon logging in, I have updated the user status from Offline to Online. So, my point would be to automatically update their status, that means change from Online to Offline if their session has ended!

I have no idea how that flow will be?
Any guidance?
Thanks...

CODE
Session.Timeout=10
If Session("security") <> "True" Then
     Response.Redirect("session_ended.asp")
End If


--------------------

Go to the top of the page
 
+Quote Post
Rakuli
post May 26 2008, 03:39 AM
Post #2


Squeeze Machine
Group Icon

Posts: 764
Joined: 13-February 08
From: Catching the squeezed drips downunder.


You would want to create a log_online table or something similar rather than just update one column in a users table.

When a user logs on, you add their user details to the log_online table (user id and time of last activity) then, when you want to see which users are online, you check only for users whose last activity was within the last 10 minutes and remove any other users from the table.


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
Monie
post May 26 2008, 07:07 AM
Post #3


Squeeze Machine
*****

Posts: 732
Joined: 13-February 08
From: Borneo


I get the idea, but with the code that I have, where it will clear the user session and force the user to log in back to the system.
That means their status is still "Online" because they have skip the logout page where the system will update their status from "Online" to "Offline" again.

CODE
Set rs = conn.Execute("UPDATE userlogin SET status = 'Offline' WHERE username =  '"& Session("user") &"'" )


So how about that?


--------------------

Go to the top of the page
 
+Quote Post
Rakuli
post May 26 2008, 07:18 AM
Post #4


Squeeze Machine
Group Icon

Posts: 764
Joined: 13-February 08
From: Catching the squeezed drips downunder.


No that's doing exactly what I said not to do biggrin.gif

Create an entire new table call it something like log_online with a few columns online_id, user_id, last_activity

When the user logs on, store them in the log_online table to mark to the rest of the site that they are online and everytime the user moves pages, update the last_activity time in this table.

Also, set a session variable to hold the user's last activity time and when they move pages, check it each time to see how long ago they last were active. If it is greater than 10 minutes ago, delete their session and their entry from the log_online table and the re-route them wink.gif


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
Monie
post May 29 2008, 02:05 AM
Post #5


Squeeze Machine
*****

Posts: 732
Joined: 13-February 08
From: Borneo


Wow, that sounds a bit confusing to me! How do you learn that Rakuli biggrin.gif
Well let me try squeeze up my brain for that great tips, thanks mate!


--------------------

Go to the top of the page
 
+Quote Post
Rakuli
post May 29 2008, 03:35 AM
Post #6


Squeeze Machine
Group Icon

Posts: 764
Joined: 13-February 08
From: Catching the squeezed drips downunder.


LOL - you sort of pick things up and come up with your own ways of doing things...

Once you've made the new table you process would look something like this... I don't know asp very well so I'll just show you the SQL I would use.

User logs in, grab their details:
CODE
SELECT * FROM users AS u
WHERE u.username = 'rakuli' AND u.password = 'password'


Store a session variable and now add their details to the new table

CODE
INSERT INTO users_online(user_id, login_time, last_activity) VALUES ($user_id, NOW(), NOW())


Now every time a user moves pages, check how long ago their last activity was (by checking the session variable)

If it was less than the allowed time update the users online table:

CODE
UPDATE users_online SET last_activity = NOW() WHERE user_id = $user_id


And update the session variable with the current time.

If it was a longer time than allowed, delete this record from the table

CODE
DELETE FROM users_online WHERE user_id = $user_id


And destroy their session and send them to the login page.


I you want to have a page or admin view where you see everyone who is online you simply delete all the records that are too old and pull out all of the others

CODE
DELETE FROM users_online WHERE last_activity > DATETIME(NOW() - 10 minutes)

SELECT * FROM users_online WHERE last_activity > DATETIME(NOW() - 10 minutes)


This will mean that if a user simply leaves your site and doesn't visit a page, they will be deleted from the online table when you view who's is on your site.


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
Monie
post May 29 2008, 04:27 AM
Post #7


Squeeze Machine
*****

Posts: 732
Joined: 13-February 08
From: Borneo


Wow, I am going to print this page and try to think for a solution back at home, thanks very much mate for the tips.
By the way, I have already leave my ASP world and right now I am in line with all of you guys in PHP biggrin.gif

After a brief reading through your idea, I have this issue that I might need to ask you later biggrin.gif
Now every time a user moves pages, check how long ago their last activity was (by checking the session variable)

CODE
If it was less than the allowed time update the users online table:

UPDATE users_online SET last_activity = NOW() WHERE user_id = $user_id

And update the session variable with the current time.

If it was a longer time than allowed, delete this record from the table

DELETE FROM users_online WHERE user_id = $user_id

And destroy their session and send them to the login page.


--------------------

Go to the top of the page
 
+Quote Post
Monie
post Sep 27 2008, 01:39 AM
Post #8


Squeeze Machine
*****

Posts: 732
Joined: 13-February 08
From: Borneo


Here is a website tutorial on Online User Counter I found just about the same idea you gave to me biggrin.gif
It's in PHP but it what important is the idea... it can easily be converted to any language once you know the method!

Thanks mate..


--------------------

Go to the top of the page
 
+Quote Post
If you found The Web Squeeze to be helpful, please donate so we can keep this site FREE, FRESH, and fortified with Web Design & Development info!
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   3 rewake 228 5th March 2008 - 02:50 AM
Last post by: Rakuli
No New Posts   5 Ryan 181 9th March 2008 - 09:07 PM
Last post by: Ryan
No New Posts   4 weasel2006 340 13th May 2008 - 01:04 PM
Last post by: weasel2006