Session vs Cookie and their relationship in web applications!
When you work with web application projects or internet environments, whether it is Frontend, Backend or DevOps, you need to understand Session & Cookie.
Understand to apply for storing local data on the Frontend side on browsers and its limitations or GET / SET their values on the servers side before sending to the client or control it in DevOps tasks when configuring Load Balancing System
Understand to control or fix bugs as well as share data stored in them between tabs in the same browser
Understand to know how to prevent and guard against hacking from a security perspective
What is a Session?
A session is used to save information on the server momentarily so that it may be utilized across various pages of the website. It is the overall amount of time spent on an activity. The user session begins when the user logs in to a specific network application and ends when the user logs out of the program or shuts down the machine.
Session values are far more secure since they are saved in binary or encrypted form and can only be decoded on the server. When the user shuts down the machine or logs out of the program, the session values are automatically deleted. We must save the values in the database to keep them forever.
What is a Cookie?
A cookie is a small text file that is saved on the user's computer. The maximum file size for a cookie is 4KB. It is also known as an HTTP cookie, a web cookie, or an internet cookie. When a user first visits a website, the site sends data packets to the user’s computer in the form of a cookie.
The information stored in cookies is not safe since it is kept on the client side in a text format that anybody can see. We can activate or disable cookies based on our needs.
Cookie is "Host Only" then the question is if it can be accessed within the same domain, what about different domains or sharing Cookies to other domains? And the answer is the “domain match” attribute or in other words, when creating a Cookie, you need to add an attribute named "domain" so that the domain set in this attribute has access rights
e.g you are running a website on the domain "learn-cookie.com" and want to share the domain "learn-session.com" to access the Cookie named "check-auth", do the following:
领英推荐
Set-Cookie: name=check-auth; domain=learn-session.com
Or allow all sub-domain of domain "learn-cookie.com" to access same Cookie, just add dot "." before domain name
Set-Cookie: name=check-auth; domain=.learn-cookie.com
Difference Between Session and Cookies
Their connection?
Software Engineer at FTS
4 个月Useful tips