Probably a noob question, but I am struggling for hours now figuring out how to do the following:
I need te reset (or set) a session variable when the user uses the back button in the browser.
Or alternatively, set a session variable at page load…
How could I do that?
M
You can use the Dynamic event of Load, when selecting the App element – then you can set your session variable.
Hmm, when I open the page, go to the app component in the app-structure panel, then add a dynamic event -> app -> load
the app component in the app-structure panel disappears and the properties panel shows some global attributes…
not a place where I can add/set variables
Sometimes the editor jumps around after adding things. If you re-select app, you should be able to set a session… assuming you have added the session manager as well.
Hey @mebeingken I think I have a similar question.
Essentially I want to set a variable on the first page load of a session. This variable will then be used in some db queries. For subsequent page loads within the same session, this variable should retain the same value set originally.
Here’s what I’ve done so far
- Create a set_session API (to create $_SESSION variable), and sc_set_session Server Connect
- Create a set_value API (to create a session_id variable that can be accessed by a Server Connect), and sc_read_session Server Connect
- Create a flow under App -> Dynamic Event -> load: if sc_read_session.data.session_id == null, then run the 2 APIs, else do nothing; the problem is that when I refresh the page, the session_id variable never seems to be null, so the variable gets re-set and re-read again every time.
Is that what I should do or should I use the Session Storage Manager as well? Are the variables set by the Session Storage Manager accessible in db queries as well?
Thanks!
If I understand your needs correctly, you are perhaps making this too complicated.
First, to answer your last question, the session manager in app connect is not related in any way to session variables you set with server connect. They are common in name only. So if you are using a server session variable, then you won’t be needing the session storage manager.
Here’s what I THINK you want:
Since you will likely use this session variable across your project, set it up as a Global variable:
Then, create a single API – It has a simple condition that creates a session id if one does not already exist, and then returns either the existing, or the new, session_id
On the front end, you then have a server connect that returns the session id:
1 Like
Thanks Ken!
What you have makes a lot more sense - I’ll try it out!