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 issue - not storing/not retrieving

I am experiencing weird behaviour with my session adapter. In my application I am using the following:

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

In my controller I have the following code

$this->persistent->searchedPhrase = "test";

This seems to be working only partialy. It does set $SESSION['searchedPhrase'] however if I want to access it on next request using $this->persistent->searchedPhrase I am getting a null value. There is no problem accessing it through $SESSION['searchedPhrase']. Another weird issue is that if I use

$this->session->set("searchedPhrase1", "test");

this variable is visible in $SESSION global only for the current request, it does not get stored for me to access it later. My $session->isStarted() is returning false, but still I am able to access a number of session variables I set in other places... The only way that now seems to be working is to add at the end of my main index.php call to sessionwrite_close()

    echo $application->handle()->getContent();
    session_write_close();

So it seems that something is interrupting saving of session data. What could be the cause?



3.3k
Accepted
answer

to clear cookie of your browser and try again:

$this->session->set("searchedPhrase1", "test");

then:

echo $this->session->get("searchedPhrase1");



5.1k

It seems to be working. Now a question to anyone who may know - since

session_write_close();

worked, I am inclined to leave it there, just in case. This shoudn't present any significant performance issue?