Complete the code to set a cookie named 'user' with value 'John'.
<?php setcookie([1], 'John'); ?>
The setcookie function requires the cookie name as the first argument. Here, the cookie name is 'user'.
Complete the code to retrieve the value of the cookie named 'user'.
<?php if(isset($_COOKIE[[1]])) { echo $_COOKIE['user']; } ?>
To check if the cookie named 'user' exists, use isset($_COOKIE['user']).
Fix the error in the code to set a cookie that expires in 1 hour.
<?php setcookie('user', 'John', [1]); ?>
The third argument of setcookie is the expiration time as a Unix timestamp. Use time() + 3600 for 1 hour from now.
Fill both blanks to set a cookie named 'theme' with value 'dark' that expires in 7 days.
<?php setcookie([1], [2], time() + 7 * 24 * 3600); ?>
The cookie name is 'theme' and the value is 'dark'. The expiration is set to 7 days from now.
Fill all three blanks to delete the cookie named 'user'.
<?php setcookie([1], [2], [3]); ?>
To delete a cookie, set its expiration time to a past time (like time() - 3600) and set its value to an empty string.