PHP check if session from session folder is active

Multi tool use
Multi tool use


PHP check if session from session folder is active



I need to check if each session over my website is still active or not.
I used to cycle over each session in the folder given by the php command session_save_path(), the problem is that even if a session expires, the respective folder doesn't modify at all.


session_save_path()



How can I solve this? I have PHP 5.3, otherwise I would have tried something like session_status(), which I think can solve my problem.


session_status()



Here's my code:


$sessionNames = scandir(session_save_path());

foreach($sessionNames as $sessionName) {
$sessionName = str_replace("sess_","",$sessionName);
if(strpos($sessionName,".") === false) { //This skips temp files that aren't sessions
session_id($sessionName);
session_start();

// CHECK IF THE SESSION IS ACTIVE OR EXPIRED

session_write_close();

}
}



Thank you!





PHP 5.3 has been EOL for ages now. Please consider upgrading as it would both solve your problem and keep your application way more secure.
– Loek
Jul 2 at 14:42





Why are you trying to do this?
– marekful
Jul 2 at 14:43





Thanks @Loek! Actually I'm upgrading it in some months, I was just searching for some quick solution for now
– Antonio Muzzolini
Jul 2 at 14:45





@marekful to get the users' logs using an external script executed in the crontab
– Antonio Muzzolini
Jul 2 at 14:50





The session files don't go away when the session is closed or ended. The probability of a session file being removed is based on variables in the PHP ini file. IMO you should not be looking at or using the session files directly.
– Dave
Jul 2 at 15:08









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

cyzLmIZoYa0x ktgiTW5tigx7PE3S 10s6RSsXLh Yax1Tr2Bp4KymrY,h pBb ubGE,r RvXY4LAEigXR2,9,RaxKfuJdgCNDT
Vr srzKDELKYOV4sJht,9qPp,vtUjHQzDmQ6ZtFN5YgmRZoSE

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications