Home / PHP Tips Generated By ChatGPT / Setting a Cookie in PHP Set a cookie that expires in 7 days. Source Code setcookie("user", "JohnDoe", time() + (7 * 24 * 60 * 60)); // 7 days echo "Cookie set.";