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 not working

Hi,

In IndexController, signin action -- where session gets created and sets some sessiom variables. Defined an hyperlink in signin.phtml, that redirects to welcome action in Index Controller. Trying to get session variables in welcome action. But, no luck and its not working.

Please, find the source code link below: TempApp


//index.php

    $di->setShared(
    'session',
    function () {
        ini_set('session.gc_maxlifetime', 3600);
        session_set_cookie_params(3600);
        $session = new Session(
            [
                "uniqueId" => "my-app-1",
            ]
        );

        $session->start();

        return $session;
    }
    );

//indexcontroller.php

          public function signinAction(){
              session_start([
                  'cookie_lifetime' => 86400,
              ]);
              echo "SignIn Action";
              $this->session->set('user-name', 'kkk');
              $_SESSION['user'] = 'green';

          }

          public function welcomeAction(){

              // Check if the variable is defined
              if ($this->session->has('user-name')) {
                  // Retrieve its value
                  $name = $this->session->get('user-name');
                  echo $name;
              }
              var_dump($this->session);

              var_dump($_SESSION);
          }

Thanks Karthik K



75.3k
Accepted
answer
edited Dec '17

Hi. Marry Christmas.

you need to regiset session servise rather thean starting the session yourself

https://docs.phalconphp.com/fr/3.2/session

Stop using any session_/set_ini functions