We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Session won't start when using uniqueId

Hi when I use session like that it won't start :

    define('UNIQUE_APP_ID', uniqid());

    $di->set('session', function() {

        $session = new Phalcon\Session\Adapter\Files(
            array(

                'uniqueId' => UNIQUE_APP_ID
            )
        );

        $session->start();

        return $session;
    });

But, when I do this it's working :

    $di->set('session', function() {

        $session = new Phalcon\Session\Adapter\Files();

        $session->start();

        return $session;
    });

Any ideas why ?

Thank you



98.9k
edited Jul '14

uniqid() always returns a different ID, this means that every call returns a different unique ID for every session which means it's impossible to recover the session data between one request and another.

Check how session_id works for more information on this functionality. https://php.net/manual/en/function.session-id.php