We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

How to get all created Phalcon session variables ?

In PHP we can loop the $_SESSION global variable to get all PHP session variables. But if I created Phalcon session variables how can I get all of them ?

edited Feb '16

Sorry i missunderstood you in first place. Will check it up and come to you if i find what you wnat.

Checked adapter soruce files, but i cannot find such method. Maybe it is intentional to not implement it?

However when storing data with Phalcon sessions the data is available in $_SESSIOn as well. So if you have a specific case to get all session data you can access it. Or even make your own session class with method like:

function getAll()
    return $_SESSION; 

I never needed to do something like you asked, but let's hope someone has fought with similar problem and will tell us :)


no ! Phalcon sessions data are not available in $_SESSION !

Are you sure? For me printing $_SESSION has same variables as Phalcon's session. What phalcon version are you using? How did you setup your session service?

edited Feb '16

my Phalcon version is 2.0.8 , build date Sep 26 2015 16:24:18.

I setup session service in the public index.php file :


use Phalcon\Loader; use Phalcon\DI\FactoryDefault; use Phalcon\Mvc\View; use Phalcon\Mvc\Application; use Phalcon\Mvc\Url as UrlProvider; use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter; use Phalcon\Session\Adapter\Files as Session;

try {

// Register an autoloader
$loader = new Loader();

// Create a DI
$di = new FactoryDefault();

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


//Handle the request
$app = new Application($di);

echo $app->handle()->getContent();

} catch(\Exception $e) { echo "Exception: ", $e->getMessage(); }



I found the solution : I must call this code in order to synchronize Phalcon sessions and PHP session :

$di = \Phalcon\DI::getDefault();
$session = $di->getSession();

So Why should I call this code to synchronize Phalcon sessions and PHP sessions ?