What potential security risks are associated with storing sensitive information like passwords in cookies in PHP?
Storing sensitive information like passwords in cookies in PHP can pose a security risk as cookies are stored on the user's machine and can be easily accessed or manipulated. To mitigate this risk, sensitive information should be stored securely on the server-side and only a reference or token should be stored in the cookie.
// Store a reference to sensitive information in the cookie
$token = generateToken(); // Function to generate a unique token
setcookie('token', $token, time() + (86400 * 30), '/', '', true, true);
// Retrieve sensitive information using the token
$token = $_COOKIE['token'];
$sensitiveInfo = retrieveSensitiveInfo($token); // Function to retrieve sensitive information using the token