Don E Posted August 28, 2015 Share Posted August 28, 2015 Hello everyone, I've done some search into the following but not sure what is the best route to take regarding sessions. If I have a cron job to do something at a certain time of the day, like delete files to free up space etc, what would be recommended to not have the cronjob delete the files where the file names of those files are stored in session for that user whose session is currently active? There is a session_status function which checks if any sessions are active but that is only for PHP 5.4 and up. Thanks. Link to comment Share on other sites More sharing options...
Ingolme Posted August 28, 2015 Share Posted August 28, 2015 It's probably better to store those filenames somewhere less volatile and more accessible, like in a database or a file. You would need to keep track of sessions using a cron job then, though. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 28, 2015 Share Posted August 28, 2015 There is a session_status function which checks if any sessions are active but that is only for PHP 5.4 and up.That still only describes the status of a single user's session, not any session on the server. But, is the version a problem for you? You're not still using a 6 year old version of PHP, are you?One option is to use a custom session handler to store your sessions in a database. Another option using the default session handler is to read every session file and parse it to check for filenames. Link to comment Share on other sites More sharing options...
Don E Posted August 28, 2015 Author Share Posted August 28, 2015 Fox and JSG, thanks for responses. PHP version is 5.3. JSG, this may abit outdated from 2004 but do you mean something like this by storing sessions in database: http://shiflett.org/articles/storing-sessions-in-a-database Link to comment Share on other sites More sharing options...
justsomeguy Posted August 28, 2015 Share Posted August 28, 2015 Yes, you use this function:http://php.net/manual/en/function.session-set-save-handler.phpIt's not a good idea to use the mysql extension at this point though, you're better off using PDO. Link to comment Share on other sites More sharing options...
Don E Posted August 29, 2015 Author Share Posted August 29, 2015 (edited) Yes, you use this function:http://php.net/manual/en/function.session-set-save-handler.phpIt's not a good idea to use the mysql extension at this point though, you're better off using PDO. Is mysqli okay? I'm sure it is but I assume you mentioned that because the article is written using the mysql extension and it's no longer recommended to use the mysql extension but just to ask, is mysqli still okay even though its not as portable as PDO? Thanks. Edited August 29, 2015 by Don E Link to comment Share on other sites More sharing options...
justsomeguy Posted August 31, 2015 Share Posted August 31, 2015 It's not deprecated or anything, so I would expect it to be around a while. It supports prepared statements, so I would suggest using those. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now