What are the potential pitfalls of incorrectly handling cookies in PHP?
Improper handling of cookies in PHP can lead to security vulnerabilities such as session hijacking, cross-site scripting attacks, and data leakage. To mitigate these risks, it is important to properly sanitize and validate cookie data, set secure flags like HttpOnly and Secure, and limit the amount of sensitive information stored in cookies.
// Set a cookie with secure and HttpOnly flags
setcookie('user_id', $user_id, time() + 3600, '/', 'example.com', true, true);