Saturday, June 9, 2018

How to keep value of variables when user moves pages from one to another

I will write what can be considered to keep value/variable when user moves pages from one to another.
  1. Use cookie. Keep the value in cookie in browser and read it later.
  2. Use DOMStorage (sessionStorage/localStorage) and keep the value in browser and read it later.
  3. Use session variable and keep the value in server and read it later.
  4. Use DB/SQL and keep the value in DB of server and use SQL to read it later.
    • Use the web framework's functionality to connect to DB and to write SQL for DB.
Or, not keeping the value, but passing the value via Get/Post method is also good if the value is not complicated data (passing ID integer for example).
I think Get method is usually used for this purpose. Sending by POST is usually used when you want to save the data in DB after receiving.