Buy Now
Sign in

Get session data in PHP

nry22 , June 21 2017
Answered
N
nry22
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.
admin
Hi Nicholas,

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


Best regards,
Max
Max
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
N
nry22
That's perfect! Thank you.
T
tshirley
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
healyhatman
Did you replace ".var" with the variable you were after?
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
T
tshirley
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
healyhatman
You CAN get the whole array if you want.
$sessiondata = \GApp::session()->get("session_name", "");
And then you can use $sessiondata["variable"];
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
T
tshirley
Yes, that works too
Thanks again
Tim