HTTP is stateless. The variables used in one page will not be available in the next pages of application unless preserved through sessions. Each page is treated as an individual transaction by the server. Each page is independent of the previous transactions. Programming languages used to create web applications offer Cookies in addition to Sessions to maintain the states of pages. State management is essential to create relationship among webpage transactions. In this post we will learn about PHP cookies for managing user state to create interactive web applications.
A cookie is a text file of a very small size and is saved in the system of the user of a website. The path and location is visible in the following image.
The data in this file is about user behavior and user preference along with the owner website and expiry date is set. This stored data is retrieved by the website whenever user visits it again. It is just like recognizing a user by a website in all her forthcoming visits.
Use of PHP Cookies
Other examples of cookies can be to display the preferred look and feel of a website as previously opted by a visitor. The PHP cookies are also used to maintain the information about what pages of a website were viewed by the user.
Are Cookies Harmful to website users?
As a user I may fear or think once to allow a website to set cookies on my system. The harmfulness of any technology lies in the user of the technology. In case of cookies the danger completely depends upon the website owner or administrator and his intention. The following features of cookies make them a trustworthy piece of information stored in your system.
- Cookies are available to be accessed by those websites which created them in your system. Cookies allow transfer of data between your system and its parent domain.
- Maximum number of allowed cookies per domain in one system is 20
- Maximum allowed size of a cookie is 4kb
- A system can have maximum 300 cookies in total to be set by all domains.
- Turning cookies off is a system owner’s prerogative. If user has set the option to turn off cookies, no domain can turn it on and set the cookies