What is Cookies in PHP?
cookie is a small piece of data sent from a website and stored in a user's web browser while the user is browsing that website. Every time the user loads the website, the browser sends the cookie back to the server to notify the website of the user's previous activity.
First time server sent the cookie information to the browser and browser stores the cookie name and the value associated with cookie. After that whenever a new request made to that site through the same browser, browser sends that cookie information to server subjected on the validity. Validity of the cookie depend upon several factor like the expiry date, path etc
Cookie information is sent in the http header, so cookie should always be created before sending any content. Otherwise php will throw error of header already sent.
We can create/edit/delete cookie in PHP by using header() function with passing the valid HTTP cookie header string.
In php using header function we can pass HTTP header request. Now
as you can see in the above HTTP header request that to create
HTTP cookie on browser we need to pass below http header request:
So if we will pass above http header using php header function
then cookie will be created with name testcookie.Below is the
code example
How to create cookies in php?
File Name :
Trending Tutorials