What is the purpose of setting a cookie in PHP?

Setting a cookie in PHP allows you to store information on the user's browser for future use. This can be useful for remembering user preferences, tracking user sessions, or personalizing the user experience. By setting a cookie, you can easily retrieve the stored information in subsequent requests, making it a convenient way to maintain state across multiple page views.

// Set a cookie with a name, value, expiration time, and path
setcookie("user", "John Doe", time() + 3600, "/");