2 Getting Started
To demystify cookies in php, we would develop a simple web app that allows users select the font style and font size to display on a website and stores this preference.
2.1 Working With Cookies
Cookies identify a user. Cookies allow web developers store a small amount of data on the user browser(not more than 4kb). Each time a request is sent to the server, the cookies stored on the browser are automatically sent with the request and can be accessed by the server.
Cookies are reliable but they are not all that secure because attackers can easily tamper with them, so you should never use cookies alone to authenticate your users or store sensitive data in cookies (e.g passwords). Users can also turn off cookies support in there browsers, so you should be careful when the core functionality of your web app depends on cookies(if your web app depends on cookies to work properly, you should always check if cookies are supported in the browser and if it is not, alert the user about the error)
2.2 Creating cookies in php
To create a cookie in php we use the setcookie(name,value,expires,path,domain,secure,httponly)
method which takes 7 parameters