Get session data in PHP

How to access session data in PHP within ChronoForms.

Overview

The issue occurs when trying to retrieve session data using incorrect variable references or expecting placeholder tags to be processed in PHP code.
Use the provided session method to get data, specifying either a specific variable or the entire session array as needed.

Answered
ChronoForms v6
nr nry22 21 Jun, 2017
I may be missing something obvious, but I can't pull the session data into PHP using the obvious:

$var = $this->data['session_name'];

$var = $this->data['session_name']['var'];

$var = $this->var['session_name'];

(and a few other variations)

I can get the session data using {session:session_name.var} but wanted to use the data in a PHP if query - and it looks like it doesn't populate the {} content till afterwards.

Or is this not built in, and I have to pull the data using regular PHP?

Many thanks,

Nicholas.
Max_admin Max_admin 21 Jun, 2017
Answer
2 Likes
Hi Nicholas,

You can use the following code in PHP:
\GApp::session()->get("session_name.var", "default");


Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
ts tshirley 07 Jul, 2018
Hello,

I tried this, using :
$mydata = \GApp::session()->get("session_name.var", "default");
And it gave me $mydata = "default". I set the "session_name" to the name of the session set in the Save to Session action.

What am I doing wrong here?

Cheers

Tim
he healyhatman 08 Aug, 2018
Did you replace ".var" with the variable you were after?
ts tshirley 08 Aug, 2018
Yep, that worked.

Thanks heaps. I was previously expecting that I would recover the entire data array and have to decode it, so I didn't consider changing to try to select only one variable.

So now I am off and running.

Cheers

Tim
he healyhatman 08 Aug, 2018
You CAN get the whole array if you want.
$sessiondata = \GApp::session()->get("session_name", "");

And then you can use $sessiondata["variable"];
ts tshirley 08 Aug, 2018
Yes, that works too🙂

Thanks again

Tim
This topic is locked and no more replies can be posted.