How to Create and Remove Cookies in PHP Web Applications and How Do They Work
First I would explain basics cookies in web applications and how they work. Then, I have listed the PHP code to create, read and remove cookies with brief description of each task. Its comprehensive post, so feel free to not read in one sitting, take breaks but absorb as you read. What are Cookies A cookie is data in the form of key value pair e.g. city=Lahore, id=90, that is stored in user's web browser. Cookies are created in web browser on the instuction of web server. Once some cookies are create/stored in web browser (we would shortly see how to create them), when user send new requests to same web application, existing cookies are automatically added in HTTP request by the web browser. So the data stored by web developer in user browsesr (in the form of cookies), automatically reaches back at server in subsequent requests. When web server send instruction to create a new cookie, it also send cookie expiry time to browser (or default time is used, explained later)...