What are the key considerations when setting an expiration time for a cookie in PHP?
When setting an expiration time for a cookie in PHP, it is important to consider the purpose of the cookie and how long it needs to persist. Setting a longer expiration time can improve user experience by remembering user preferences, but it can also pose a security risk if sensitive information is stored in the cookie. It is recommended to set a reasonable expiration time based on the specific use case of the cookie.
// Set a cookie with an expiration time of 1 hour
$cookie_name = "user";
$cookie_value = "John Doe";
$expiration_time = time() + 3600; // 1 hour
setcookie($cookie_name, $cookie_value, $expiration_time, "/");