What is the default behavior for the lifespan of cookies in PHP?
By default, cookies in PHP have a lifespan of 0, which means they will expire when the browser is closed. To set a specific expiration time for a cookie, you can use the `setcookie()` function with an additional parameter specifying the expiration time in seconds from the current time.
// Set a cookie with a lifespan of 1 hour
setcookie("cookie_name", "cookie_value", time() + 3600);
Keywords
Related Questions
- In what scenarios would it be more beneficial to preload images using JavaScript instead of PHP in a web application?
- How can the "Undefined index: img" error, mentioned in the forum thread, be resolved when trying to set a session variable in PHP?
- Are there any best practices for handling page redirection in PHP when using if-else statements?