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

the session variable works?

Hello I am doing an address if the session variable is empty or not started session previously works in phalcon 2.013 and php 5 I was wondering if they have changed the functions to version 7.2

<?php
if ($this->session->has("userId")) {

    //   Retrieve its value
    $name = $this->session->get("userId");
} else {
    header("Location:" . $this->url->get('inicio/inicio'));
}
?>

You need first start session service before using session, it's not started by default, there is issue for this - https://github.com/phalcon/cphalcon/issues/12921

Not sure if it was working or not in php5, but for sure it wasn't started too so most likely it was broken.



81.1k

I start the session in the services.php file, it is necessary to start it again?



/**
 * Start the session the first time some component request the session service
 */
$di->setShared('session', function () {
    $session = new SessionAdapter();
    $session->start();

    return $session;
});

No, it should work already.