Sessions and cookies do not match at all. Cookies are a client side. Server side sessions. Sessions often (but not necessarily) use cookies to relate one request to another from the same user to determine that they belong to the same session.
A session is an artificial concept, and HTTP does not have this concept. It is created by web servers to help web developers transfer information on request, such as user account information, shopping carts, form data, etc. A cookie is transmitted by standard HTTP headers.
The information that you store in the session and not in the cookie is up to you. Usually, you put cookies into the cookies that you want to save during the sessions after the user closes his browser. Maybe remembering authentication tokens to implement the “remember me” function or past user actions to personalize his / her experience. Keep this information small and “reference”, that is, it can simply be identifiers that refer to the richer information that you store on the server side. Remember that the client side is more vulnerable to malware, so do not store passwords and confidential information.
Finally, there is also a local repository that you have not mentioned. This is also on the client side, but perhaps a little less prone to cross-site scripting hacking, because, unlike cookie data, they are not sent automatically in the headers.
jbx Jul 03 '19 at 19:50 2019-07-03 19:50
source share