Cookie expiration and security
📖 Scenario: You are building a simple PHP web application that uses cookies to remember user preferences. To keep users safe and improve their experience, you need to set cookies with proper expiration times and security flags.
🎯 Goal: Create a PHP script that sets a cookie with a specific expiration time and security settings, then displays a message confirming the cookie is set.
📋 What You'll Learn
Create a cookie named
user_preference with the value dark_mode.Set the cookie to expire in 7 days.
Ensure the cookie is only sent over secure HTTPS connections.
Make the cookie inaccessible to JavaScript by setting the HttpOnly flag.
Display a confirmation message that the cookie is set.
💡 Why This Matters
🌍 Real World
Cookies are used in websites to remember user settings like themes or login status. Setting expiration and security flags helps protect user data and improve experience.
💼 Career
Web developers must know how to manage cookies securely to protect users from attacks like session hijacking and to comply with privacy standards.
Progress0 / 4 steps