Cookies in PHP – Create, Set, Read and Delete a Cookie

HTTP is a stateless protocol. It means user sends a request, a server responds to that request without remembering the request later. To track important information (such as user preference, user activity etc.) on a website cookies are very useful. In this blog post, I’ll explain what is cookies. How to create, set, read and delete a cookie in PHP.

what is Cookies

Cookies are very useful to store small information in a remote browser (user browser). It’s a simple text file which stores maximum 4KB of data.

Cookies are created by a browser on the request of a server (as per program logic). Once a cookie is created on a user browser, the browser sends that cookie information back to the server using HTTP Header.

How to Store & Retrieve an Array Value in a Cookie

How to store and retrieve an array value in a cookie.  Cookies can only store string values. You cannot store an array directly into a cookie. In this article, We’ll discuss how to store and retrieve an array value from a cookie.

My previous post related to Cookies.

1. How to create, read, update and delete  a cookie in PHP

2. How to set a cookie on multiple subdomains

 

How to Set Cookies for Multiple Subdomains

cookies

How to set cookies for multiple subdomains. In this post, You’ll learn how to set and read a cookie across multiple subdomains.

HTTP is a stateless protocol it means requested resource is served without the server remembering the request later. So how website knows whether you are a unique user or you have visited previously. How they remember your previous browsing history, language preference etc.