Interview question
How do you set and retrieve cookies in PHP? PHP में cookies कैसे set करें?
Answer
setcookie('user_preference', 'dark_mode', [
'expires' => time() + (30 * 24 * 60 * 60),
'secure' => true,
'httponly' => true,
'samesite' => 'Strict'
]);
echo $_COOKIE['user_preference'] ?? 'light_mode';setcookie('user_preference', 'dark_mode', [
'expires' => time() + (30 * 24 * 60 * 60),
'secure' => true,
'httponly' => true
]);
echo $_COOKIE['user_preference'] ?? 'light_mode';Was this answer clear?