Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Session won't start

Hi, I can't get my session to start.

I'm having this piece of code in my services.php config file :

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

        $session = new Phalcon\Session\Adapter\Files();
        $session->start();
        return $session;
    });

In my logging function I'm setting a session variable like that :

    $this->session->set('auth', array(

        'id' => $user->ID,
        'name' => $user->Firstname . " " . $user->Lastname,
        'roleID' => $role->ID,
        'role' => $role->RoleName,
        'module' => $userModule
    ));

And in my security class, I do this :

    $auth = $this->session->get('auth');

When I login, I'm redirect to the main page, but when I click on a new link, it's like I'm not logged in. It returns me to the login page.

This happen since I upgrade to phalcon 1.3.1 form 1.2.4.

My login scheme is base on INVO example, it was working fine before I upgrade.

Thank you !

try to set session service as shared

$di->set('session', function() {
    $session = new Phalcon\Session\Adapter\Files();
    $session->start();
    return $session;
}, true);

or

$di->setShared('session', function() {
    $session = new Phalcon\Session\Adapter\Files();
    $session->start();
    return $session;
});


17.7k

Hi !

Nope. Doesn't works. :(

Thanks

so, check if it works if you add at the begining of index.php

session_start();

will then your application work?



17.7k

Same, result.



17.7k

I just find out this post in github :

https://github.com/phalcon/cphalcon/issues/2241

I'm will give it a try.

edited Apr '14

Did you inject the DI into your security class ?

Edit : Use var_dump($_SESSION); die(); in your securiy class to know if you have somes sessions added.



17.7k
Accepted
answer

The session start, it just don't hold on. When I click on a link, it return me to the login page. The solution is there : https://github.com/phalcon/cphalcon/issues/2241