The web servers host the website. The client-server makes a request for data from the webserver and the webserver fetches the required pages and responds to the client by sending the requested pages. The web server communicates with the client-server using HTTP (HyperText Transfer Protocol). HTTP is a stateless protocol which means the server needs not to retain the user information once the transaction ends and the connection is closed. The web browser is an example of a client-server which communicates with the web server using HTTP. HTTP prevents long engagement of the client with the webserver and the connection is closed automatically once the request is serviced. But often it is required to store the user information for future references. One of the most common uses of cookies is for authentication. Cookies serve the purpose of retaining user information even when the connection is lost. Cookies are data, stored in text files, on the computer.
Cookies comprise of five variable fields:
- Expires:Specifies when the cookie will expire. If left empty the cookie expires immediately when the connection is lost.
- Domain: Specifies the domain name of the website.
- Name=Value: Cookies are stored in the form of name-value pairs.
- Path: Specifies the webpage or directory that sets the cookie.
- Secure: Specifies whether the cookie can be retrieved by any server (secure or non-secure).
However, cookies can store only a small amount of data like userID or sessionID. Clearing the cookies will logout the user of every site that it had logged in. HTTP can be made stateful by using cookies. Stateful web applications store the information from the previous requests and can use it for serving future requests.
- Creating Cookie:
- Reading Cookie:
- Cookie Tracking and Stealing using Cross-Site Scripting
- Express Cookie-Parser - Signed and Unsigned Cookies
- Firebase (sign in with Google) Authentication in Node.js using Firebase UI and Cookie Sessions
- HTML | DOM cookie Property
- Remove a cookie using PHP
- HTTP headers | Cookie
- HTTP headers | Set-Cookie
- Express.js res.cookie() Function
- How to read and write JSON file using Node.js ?
- How to Read and Write the Files in Golang?
- How to create dictionary and add key–value pairs dynamically?
- Dirty read in SQL
- Node.js REPL (READ, EVAL, PRINT, LOOP)
- How to read Competitive Programming Questions?
- How to read if a checkbox is checked in PHP?
- How to read any request header in PHP
- Getting started with React Native? Read this first !
- CSS | :read-only Selector
- CSS | :read-write Selector
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.