How can a cookie be set to expire on a specific date and time in PHP?
To set a cookie to expire on a specific date and time in PHP, you can calculate the expiration time by adding the desired number of seconds to the current time using the `time()` function. Then, use the `setcookie()` function to set the cookie with the calculated expiration time.
$expiryTime = strtotime('2023-01-01 00:00:00'); // Set the desired expiration date and time
setcookie('cookie_name', 'cookie_value', $expiryTime);
Keywords
Related Questions
- Are there any PHP frameworks or libraries that can simplify the process of creating a login/register system?
- What are some best practices for handling timestamp calculations and rounding in PHP to ensure accurate statistical analysis over different time periods?
- What are the potential pitfalls of using references in PHP?