Get a list of all PHP session_id

Can't get a list of everyone session_idin PHP SESSIONS?

Note: I need a file on the server. One file is equal to one session. And I need to determine the behavior of old files if SESSION expires.


Thanks to everyone for any advice.

+5
source share
3 answers

I would do it in an old project.

i named files with session_id (something like: sessionid_some_file.tmp):

_TMP_PATH_: the path by which files are scanned.

foreach(new DirectoryIterator(_TMP_PATH_) as $file)
{
    if(preg_match('/(.*)_(.*)_(.*)\.tmp/', $file->getFilename(), $data))
    {
        session_write_close();
        $session_id = $data[1];
        session_id($session_id);
        session_start();
        if(empty($_SESSION))
        {
            unlink(_TMP_PATH_ . $file->getFilename()); 
        }
    }
}
session_write_close();

foreach files i get session_id, open it and check something inside. (I wrote something after opening each session)

But be careful, this piece of code has never been in a production environment.

+1

, , session.save_path php.ini, .

- session_set_save_handler(). , .

+3

The best you can do to get a list of all existing session identifiers:

preg_grep("/^sess_/", scandir(ini_get("session.save_path")))

But that will not tell you which files are still valid. And I do not understand the second part of your question. But they can be unesterified manually to define attributes.

+2
source

All Articles