Cookie & Session
Cookie and Session
In HTTP, it is unreliable, so, they forget the users, the users need to authorize every single time.
So, Cookie and session helps them keep authorizing to the website.
Cookie
A file that stores keys and values (name, time, path, address) in “Client Local”.
- Web browser requests to server
- Create Cookie to keep holding their information
- Attach Cookie on HTTP header and send it when server requests
- Web browser manages Cookie, send Cookie with HTTP in next request
- Server checks the previous information in Cookie, and response
e.g. ID, Password
Session
A time that keep holding the statement from access to finish in server through web browser.
- Web browser requests to server
- Server allocate ID to the web browser
- Put Session ID into Cookie with HTTP and send it to server when server response
- Web browser sends them again until close the web browser
- Server checks session ID and the previous information about session ID, and response
Session also use Cookie for keeping statement.
e.g. Login
The difference between Cookie and Session
Storage location
-Cookie : Client
-Session : Server
Security
-Cookie : not secure, because it stores in Client
-Session : secure, because it only store session ID in Client
Duration
-Cookie : Client still have data
-Session : Client only have session ID, not data
Speed
-Cookie : fast, because it stores in Client
-Session : slow, becuase the actual data is in Server