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

Recommended Answers

All 10 Replies

Member Avatar for P0lT10n

do this for logout.php

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

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

Hello Sumit,
I don't know the exact solution to you problem but the following link may be useful to you.
Session logout

Forum

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.

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?

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

Member Avatar for P0lT10n

that would be a time out... i dont know how to do that :S

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?

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.

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.