Reading Time: < 1 minute
A cookie is a “text file” that is stored in the browser and collects various information from a webpage, such as identifying user preferences, displaying relevant content based on searches, and most importantly, remembering user access and credentials.
Let’s see how to work with cookies in PHP.
- CREATE COOKIE:
setcookie(name, content, expiration, path, domain, secure, httponly) // The last parameter is a boolean value, meaning it should be set to true or false.
You don’t need to fill in all the fields, just the ones you need or want.
- DELETE COOKIE:
Here are 2 ways to delete a cookie:
// Set the expiration to the past and set the cookie value to null setcookie('name', '', time() - 3600); // Delete the cookie by just specifying its name setcookie('name');
That’s all for today! I hope you like it, but most importantly, I hope it helps you. See you in the next one.