shlomikalfa Posted November 6, 2008 Share Posted November 6, 2008 how do i make them stick?! it's like they are auto-deleted all the time and my users are set logged-out! i want to use an own made function to delete session files based on "filemtime()" function... is that a good idea ?! This is the function i have now, it should check if the user haven't modified his session file in the last hour and if so deletes it.... P.S my users are modifying their session file on every page change. function getUsersOnline() { $count = 0; $handle = opendir(session_save_path()); if ($handle == false) return -1; while (($file = readdir($handle)) != false) { if (ereg("^sess", $file)){ // Make sure this session has been accessed in the last MAX_IDLE_TIME time. if(time()- filemtime(session_save_path() . '/' . $file) < MAX_IDLE_TIME * 60){ $count++; }else{ @unlink(session_save_path() . '/' . $file); } } } closedir($handle); return $count; } Link to comment https://forums.phpfreaks.com/topic/131605-solved-making-session-files-stick-forever-never-deleted/ Share on other sites More sharing options...
ILMV Posted November 6, 2008 Share Posted November 6, 2008 By default, PHP sessions last only 24 minutes (if I am not mistaken), a session may also be cleared if the browser is closed. How often is the session cleared? Link to comment https://forums.phpfreaks.com/topic/131605-solved-making-session-files-stick-forever-never-deleted/#findComment-683526 Share on other sites More sharing options...
shlomikalfa Posted November 6, 2008 Author Share Posted November 6, 2008 well... it seems like it's being cleared after 1 hour or maybe 2 hours.... i tried: ini_set("session.gc_maxlifetime", "518400"); which seems like it doesn't work..... P.S my sessions are in a folder inside my root-dir.... and not in main folder... Link to comment https://forums.phpfreaks.com/topic/131605-solved-making-session-files-stick-forever-never-deleted/#findComment-683531 Share on other sites More sharing options...
ILMV Posted November 6, 2008 Share Posted November 6, 2008 You do realise that session wil lase for 6 days... I am not sure, but that might be over the maximum session time? Link to comment https://forums.phpfreaks.com/topic/131605-solved-making-session-files-stick-forever-never-deleted/#findComment-683542 Share on other sites More sharing options...
shlomikalfa Posted November 6, 2008 Author Share Posted November 6, 2008 that suppose to be 72 hours.... but it doesn't work.... please tell me how to set it to at least 48 hours.... Link to comment https://forums.phpfreaks.com/topic/131605-solved-making-session-files-stick-forever-never-deleted/#findComment-683545 Share on other sites More sharing options...
luca200 Posted November 6, 2008 Share Posted November 6, 2008 ini_set("session.gc_maxlifetime", "518400"); Why don't you use a .htaccess parameter instead of that? It's hard to be sure that this setting is present on EVERY page that could access your session directory Link to comment https://forums.phpfreaks.com/topic/131605-solved-making-session-files-stick-forever-never-deleted/#findComment-683548 Share on other sites More sharing options...
shlomikalfa Posted November 6, 2008 Author Share Posted November 6, 2008 why half answers guys ?! .htaccess no prob, but how do i do that ?! what should i write in there ?! Thanks for the help... Link to comment https://forums.phpfreaks.com/topic/131605-solved-making-session-files-stick-forever-never-deleted/#findComment-683554 Share on other sites More sharing options...
shlomikalfa Posted November 6, 2008 Author Share Posted November 6, 2008 ohhh can't modify post... -> can anyone please explain me exactly what does "session.gc_maxlifetime" means ?! -> Does this ""Garbage collector" delete only files that haven't been modified in the last "session.gc_maxlifetime" time ?! or does it delete any file that exists more then "session.gc_maxlifetime" time ?! -> Will setting my "session.gc_maxlifetime" to 72 hours but yet having my function: function getUsersOnline() { $count = 0; $handle = opendir(session_save_path()); if ($handle == false) return -1; while (($file = readdir($handle)) != false) { if (ereg("^sess", $file)){ // Make sure this session has been accessed in the last MAX_IDLE_TIME time. if(time()- filemtime(session_save_path() . '/' . $file) < MAX_IDLE_TIME * 60){ $count++; }else{ @unlink(session_save_path() . '/' . $file); } } } closedir($handle); return $count; } have the effect of deleting files only if their not modified for over a desirable time ?! Link to comment https://forums.phpfreaks.com/topic/131605-solved-making-session-files-stick-forever-never-deleted/#findComment-683568 Share on other sites More sharing options...
luca200 Posted November 11, 2008 Share Posted November 11, 2008 -> can anyone please explain me exactly what does "session.gc_maxlifetime" means ?! It's time (in seconds) after which garbage collector can throw sessions away -> Does this ""Garbage collector" delete only files that haven't been modified in the last "session.gc_maxlifetime" time ?! or does it delete any file that exists more then "session.gc_maxlifetime" time ?! None of the two. The right answer should be "only files that haven't been opened in the last 'session.gc_maxlifetime' time". On Linux systems, at least. For Win, the first of yours should fit. -> Will setting my "session.gc_maxlifetime" to 72 hours but yet having my function: ............. have the effect of deleting files only if their not modified for over a desirable time ?! The main point is that if your sessions are in a shared directory, raising up 'session.gc_maxlifetime' will have no effect at all. Link to comment https://forums.phpfreaks.com/topic/131605-solved-making-session-files-stick-forever-never-deleted/#findComment-687611 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.