Clarity on Behaviour of Server Side $_SESSION variables

So my app is making different database calls and retrieving data that I don’t want to pass to the client side.

I also don’t want to go to the database and retrieve any information more than once.

Hence I want to store some of that retrieved information purely on the server side.

Am I right in saying I should use $_SESSION variables on the server side for this?

When I see @George and @Teodor saying:

Can you please clarify for me what “while the PHP user session is active” actually means in reality?

Is it:

  1. Is it from when the user visits the page to when the tab on the browser is closed?
  2. Is it from when the user visits the page to a security logout?
  3. Is it from when there is a security login to a security logout?
  4. Is it time limited in some way?

So I’ve started reading around articles like this one.… and it seems like:

  • A “session” gets stopped and started and session variables can then be created within that session time window.
  • A session by default can be started as the page is visited by setting session.auto_start = 1 in the php.ini file.
  1. So assuming for now that session.auto_start is set to 0, does the Security Provider Login action start a Session? Or does page load start it in how Wappler is set up?

Also…
6. What happens to the session data if the user hits refresh on the browser? Are all the values cleared or do I need to clear them if that is what I want?
7. Is there any limit on the quantity of data that can be stored in total?
8. Is there any limit on the quantity of data that can be stored in one variable?

But then…
9. What is the difference betwen a $_SESSION and a $_SERVER variable?

And finally, …
10. If I am running in an auto-scaled environment like AWS offers, then I presume that once a user session is started then all requests for that session will be routed to the same ec2 server instance where the correct session variables can be found…

Any clarity would be greatly appreciated!

Many thanks,
Antony.

Hello,
Please check what a PHP session is:
https://www.w3schools.com/php/php_sessions.asp

What PHP global variables are:
https://www.w3schools.com/php/php_superglobals.asp

What a browser session is:
https://www.w3schools.com/jsref/prop_win_sessionstorage.asp

Thanks for that @Teodor, I will look very closely at those.

Please can you tell me if and when the Wappler environment creates and ends sessions?

If you’re developing on a local machine, you can view the contents of session files as they are created/modified - in the same way you can view data as it’s created/modifed in local storage for example. This would probably help answer most of your questions, though the settings on your local and remote server may not be exactly the same. (You may be able to access the session files on a remote server too.)

To access the session file, find the file name in developer tools, under cookies:

image
… and then open the file (eg C:\wamp64\tmp\sess_r2ct5qpl71rksqfp6fqc9iasfh) in a text editor. If you login, you’ll see something like this appear:

sec_provId|i:313;

If you store more data in the session, you will the contents updated.

2 Likes