Cookie and Session store state in HTTP
Usually, server does not remember what client make requests. It treats every requests from a new anonymous client. If server want to provide personalized service(login state, exercise records of sports, saved favourite blog post) to the client, it must know the client and send back the relevant data. Cookie and Session is used to help recognize the client.
Session is a storage space and cookie is s small piece of data. Both are created by the server. When server want to remember the client, it saves client information into Session with a unique ID. Then server creates a cookie that contains this Session ID. Server sends back the data requested by the client associated with the cookie. The client save the cookie.
Next time, the client send new request to the same server with the cookie saved. The server check the cookie and extract the Session ID for search. If the server find the record in Session, then server know the client and can provide personalized service.
The diagram below is a simply workflow.

Comments
Post a Comment