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:
- Remove a cookie using PHP
- HTTP headers | Set-Cookie
- Express.js res.cookie() Function
- HTML | DOM cookie Property
- HTTP headers | Cookie
- Cookie Tracking and Stealing using Cross-Site Scripting
- Express Cookie-Parser - Signed and Unsigned Cookies
- CSS | :read-only Selector
- Dirty read in SQL
- Node.js | fs.read() Method
- PHP | XMLReader read() Function
- PHP | Gmagick read() Function
- How to read any request header in PHP
- CSS | :read-write Selector
- How to read a hash with an “&” sign in the URL ?
- How to read if a checkbox is checked in PHP?
- Console.Read() Method in C#
- Node.js fs.Dir.read() Method
- How to read user or console input in PHP ?
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.