Buy Now
Sign in

Get session data in PHP

nry22 , June 21 2017
N
nry22 20
June 21 2017 #369651
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 26.0
June 21 2017 #369656
2
 Answer
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 20
June 21 2017 #369667
1
That's perfect! Thank you.
T
tshirley 256
July 07 2018 #378870
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 5.2
August 08 2018 #379493
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

You can now copy+paste code from forums
T
tshirley 256
August 08 2018 #379494
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 5.2
August 08 2018 #379495
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

You can now copy+paste code from forums
T
tshirley 256
August 08 2018 #379497
Yes, that works too
Thanks again
Tim