Jump to content

delete query and destroy session when browser close


zohab

Recommended Posts

Hi,

 

In my site,

 

When user login then I set username,uniqueid in session and create new entry in active users section.

When user logout then i destory session and delete entry in active_users section.

 

example

 

A.user1 login then

 

1.$_SESSION['user1name'];$_SESSION['uniqueid'];

2.insert into active_users (uniqueid,username) values('1','user1name');

 

B.user1 logout

 

1.session_destory();

2.delete from active_users where username='user1name' and uniqueid='1';

 

 

When user click on logout link then he will be logout and operation B is perform.

 

when user close browser then session_destroy() but active_user table entry does not

update because i do not know that user close the browser.

 

How can I delete entry from active users table when user close browser.

 

Link to comment
Share on other sites

As PHP is not a syncronous technology, that is to say there is not a permanent flow of data between the client and the server, you will probably need to track the time period since the user last accessed a page and logout after a period of time.

 

So your active_users table will have a field for last_access, whenever a visitor views a page that displays a list of active_users you would compare the current time to the last_access time for all active users and remove any that have been longer than your timeout period before displaying the list.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.