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 check session set or not?

if(isset($_SESSION['sessionToken'][''profile])) { } The above code was check the session or not in core php. how to handle in phalcon. if($this->session->has("sessionToken")['profile']) { } I tried in phalcon..Not able to check array of session in phalcon. anybody help me

edited Jun '17

If I understand, "sessionToken" is an array. I'd tried something like this :

if($this->session->has("sessionToken") && is_array($this->session->get("sessionToken")) 
        && array_key_exists('profile', $this->session->get("sessionToken"))) {}

Thanks Nikolay for typo correction ;)

edited Jun '17

@Elroliv, Just a typo :)

// These
array_key_exists('profile', $this->session->has("sessionToken"))

// Should be 
array_key_exists('profile', $this->session->get("sessionToken"))

// Or
array_key_exists('profile', $this->session->sessionToken)

edited Jun '17

You're right, I'd just typed too quickly ;o))

you can use:


$this->session->has("session_name") // returns bool $this->session->get("session_name") // returns session value $this->session->set("session_name","value') // sets session value