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.

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.