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



2.1k
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
is_array($this->session->has("sessionToken"))
array_key_exists('profile', $this->session->has("sessionToken"))

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

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


2.1k
edited Jun '17

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

you can use:

´´´php

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

´´´