I must understand how to see if an PHP session continues to be alive, because of confirmed ID. That or anything that could produce accessibility active session's list.

I've discovered some related information on the web, but could not really obtain a proper answer.

To inform you a little concerning the background, I'm writing an internet site that enables customers to change content (let us say articles, for example). And also, since I'm not going these to customize the same resource simultaneously, I needed to consider a protection's system.

Therefore the idea was that every opened up resource could be locked and connected having a session ID. When finished, the consumer would free it. However nothing prevents him from just closing your window, letting this content kept in writing.

Therefore I must have the ability to see if a session continues to be alive, and when a lock continues to be legitimate.

There is a really quite simple solution for the problem:

When opening the page, keep userid and also the current timestamp in certain posts employed for securing the element. Around the page, include some JavaScript to call some script every minute that updates the timestamp - in order lengthy because the user is in this article the timestamp should never be over the age of one minute. Simply prevent others from editing exactly the same element unless of course the timestamp is over the age of one minute (along with a couple of seconds).

I understand this can be a older question however the "best" response to your real question is found here: http://www.codeguru.com/forum/archive/index.php/t-372050.html

Here's what it states: The php.ini file consists of an environment known as sesison.save_path, this determines where PHP puts files that have the session data. When a session is becoming stale, it will likely be erased by PHP throughout the following garbage collection. Hence, an evaluation for the existence of a fiel for your session ought to be sufficient to find out if the session continues to be valid.

$session_id = 'session_id';
$save_path = ini_get('session.save_path');

if (! $save_path) {
$save_path = '.'; // if this vlaue is blank, it defaults to the current directory
}

if (! file_exists($save_path . '/sess_' $session_id)) {
unlink($session_id); // or whatever your file is called
}