Ask Apache if session still exists from id

I would like to know how to check if a PHP session is alive thanks to a specific id. This or something that could give me access to the active session list.

I found some related information on the Internet, but could not get the correct answer.

To talk a little about this, I am writing a website that allows users to modify content (say, articles, for example). And since I do not want them to change the same resource at the same time, I had to think about a protection system.

Thus, the idea was that every open resource would be locked and associated with a session identifier. When done, the user will release it. But, of course, nothing prevents him from simply closing the window, allowing the content to block it in writing.

Therefore, I should be able to check if the session is alive, and if the lock is still legal.

+3
source share
2 answers

There is a pretty simple solution for your problem:

, . JavaScript, script , - , , 1 . , 1 ( ).

+2

, , "" : http://www.codeguru.com/forum/archive/index.php/t-372050.html

: php.ini sesison.save_path, , PHP , . , , PHP . , , , .

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

if (! $save_path) {
$save_path = '.'; // if this value 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
}
+2

All Articles