I am setting up a business guide and would like to know if it is better to use a cookie or session to store the client id_city of which it belongs on the first access;
I am setting up a business guide and would like to know if it is better to use a cookie or session to store the client id_city of which it belongs on the first access;
Sessions are destroyed when the browser is closed (unless the visitor selects the option to continue from where they left off in the browser), since cookies remain valid for as long as you determine, or until the client deletes them.
Knowing this, it's easy to decide which one to use. In your case, I believe cookies are more interesting because if you set a meaningful expiration date, some other day when it comes back, it will be the way it left it.
Remember: never save important information (passwords or personal data) in plain text in a cookie, preferably do not save this type of client-side data, since anyone with access to the computer can view such data.
I will not go into this subject here because it leaves your question, but if you have interest, just search here in Stackoverflow or Google itself, you will have a lot of information about it.
Possible duplicate of What difference between Sessions and Cookies and Session C # how does it work? >
Copying the brief explanation ....
Cookie is a storage mechanism for your client-side variables. It is stored physically on the client computer by the browser. Different users on the same computer can read / use the same cookie.
Because of this (some comments):
The Session is also a storage mechanism for your variables, but server-side. By default, the session stores its data in server memory. But you can configure to store by SQL Server, for example. The same user can run two or more browsers and each browser has its own session.
That is:
The circumstance of use will depend on your scope and what you will store ...
In your case
I would use Session, since we are talking about a sensitive data ...