6 Data storage and sessions
An important topic in web development is providing a good user experience, but the fact that HTTP is a stateless protocol seems contrary to this spirit. How can we control the whole process of viewing websites for users? The classic solutions are using cookies and sessions, where cookies serve as the client side mechanism and sessions are saved on the server side with a unique identifier for every single user. Note that sessions can be passed in URLs or cookies, or even in your database (which is much more secure, but may hamper your application performance).
In section 6.1, we are going to talk about differences between cookies and sessions. In section 6.2, you’ll learn how to use sessions in Go with an implementation of a session manager. In section 6.3, we will talk about session hijacking and how to prevent it when you know that sessions can be saved anywhere. The session manager we will implement in section 6.3 will save sessions in memory, but if we need to expand our application to allow for session sharing, it’s always better to save these sessions directly into our database. We’ll talk more about this in section 6.4.
Links
- Previous Chapter: Chapter 5 Summary
- Next section: Session and cookies