What is the purpose of using cookies in PHP?
Cookies in PHP are used to store small pieces of data on the client's machine. They are commonly used to remember user preferences, track user sessions, and personalize user experiences. By using cookies, developers can create more dynamic and interactive web applications.
// Set a cookie with a name, value, expiration time, and path
setcookie("user_id", "12345", time() + 3600, "/");
// Retrieve the value of a cookie
$user_id = $_COOKIE["user_id"];
// Delete a cookie by setting its expiration time to a past time
setcookie("user_id", "", time() - 3600, "/");