0

Dear Friends,

I am following the bestuff.com's active member session.
I am doing the following thing...
1. when user logs in, I update my database's field with value 'O' (means user is logged in and fires query which has flag value 'O')


But the problem is how to check user's status when User closes browser?

I set 10 minutes session time out but it only works when user refreshes or visits the page.

Please help me out of this... hell...

Please reply me fast and please admin section also take part in this query/problem...

Thanks in advance

index.php
----------

session_start();
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 600))
{
    // last request was more than 30 minates ago
    //session_destroy();   // destroy session data in storage
    //session_unset();     // unset $_SESSION variable for the runtime
    header("location:logout.php");
}
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp

logout.php
----------

session_start();
include_once 'commoninclude.php';
$objLogin=new MySQLConnection();
$objLogin->Open();
$updateMemberOnlineStatus="Update tblMemberRegistration Set OnlineStatus='F' Where ID=".$_SESSION['memberid'];
$objLogin->UpdateQuery($updateMemberOnlineStatus);
$objLogin->Close();
session_unset();
session_destroy();
header("location:index.php");

but the above code does not working...

please help

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

5
Contributors
10
Replies
12
Views
7 Years
Discussion Span
Last Post by joshisumitnet
0

do this for logout.php

Update tblMemberRegistration Set OnlineStatus='F' Where ID='".$_SESSION['memberid']."'"

Edited by P0lT10n: n/a

0

Dear P0lT10n,

Update query is executing perfectly when we logout force fully or when browser is opened and session is time out.

My problem is how to logout when user closes browser?

When user closes browser, there should be some code to handle that browser close problem.

Please work out on that.

Thank you for reply.
Sumit Joshi

0

Dear Chintan,

Thanks for reply.
My problem is when user closes browser, automatically database table must be updated.

My problem is that I am not able to execute query on browser's close event.

Seeking good help.

0

If you absolutely must run the query when the user closes the browser, you can trigger some Javascript on the close() event for the window. That Javascript can make an AJAX call to a PHP page that does the logout.

However, my question is whether you really need to logout on window close. I presume you're using PHP sessions - which automatically expires when the browser is exited. So, as far as user security, that's handled.

If the database sessions aren't updated until the next page load by someone - what's the harm? Does it really matter that there's an expired session hanging around if no one is accessing the site?

0

Dear Friend,

Thank you for you time and reply.

See my exact problem
1. visit http://bestuff.com
2. At the last there is section of "Active Members", in which it shows top 40 to 44 users who are online.
3. When I get logged in, I will be shown on that list because I just logged in last.
4. When I close browser without logging out force fully then my profile image will be removed from that section.

If you have any other solution for that please help me that how to do?

Thanks in advance.
Sumit Joshi

0

Dear Friends,

Ok I agree with you that it's time out.
But how I able to check from Server that User has session time out and then update the table?

0

amit if you have set the session time for 10 minute.so then it does't matter that user close the browser. session will automaticaly destroyed after 10 minute.

0

amit if you have set the session time for 10 minute.so then it does't matter that user close the browser. session will automaticaly destroyed after 10 minute.

Dear Freddavis,

You all right that when browser get closed all session varialbes will be destroyed.

My main and serious problem is how to Update table when browser get closed?

I am finding this answer since long time and have visited most websites and forums but could not found solutions yet.

Is there anybody who can solve this?
Is there any expert in daniweb who can solve my problem?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.