Contents
The main difference between a session and a cookie is that session data is stored on the server, whereas cookies store data in the visitor’s browser. Sessions are more secure than cookies as it is stored in server. Cookie can be turned off from browser.
SO YOU ARE PROBABLY WONDERING WHAT IS THE DIFFERENCE BETWEEN A TOKEN AND A SESSION_ID STORED IN A COOKIE: The difference is that tokens are typically following a standard while sessions are implemented as needed by the server. Additionally, tokens tend not to need a session on the server but they may have one.
What’s the difference between Cookie and session based authentication?
Along with the web-client cookie, if a web-server stores the user authN data in their back-end, then it will be called Session-based authentication.
How is session data stored on a cookie?
The server can then verify the session data on the cookie with the session data stored in the server memory when the user logged in initially. When the user logs out from the website, that session data is deleted from the database and the server memory. In token-based authentication, we use JWTs (JSON Web Tokens) for authentication.
Before the emergence of JSON Web Tokens, we predominantly used this type of authentication. In this type of authentication method, the server is responsible for the authentication and the client does not know what happens at the server side after sending a request. So what is session cookies?
Using Session Cookies Vs. JWT for Authentication HTTP is a stateless protocol and is used to transmit data. It enables the communication between the client side and the server side. It was originally established to build a connection between web browsers and web servers. Let’s understand this with the help of an example: