Complete the code to set a cookie named 'user' with value 'John'.
<?php setcookie('user', 'John', [1]); ?>
The third parameter of setcookie is the expiration time in Unix timestamp format. Using time() + 3600 sets the cookie to expire in one hour.
Complete the code to set a secure cookie that is only sent over HTTPS.
<?php setcookie('session', 'abc123', time() + 3600, '/', '', [1], true); ?>
The sixth parameter of setcookie controls the 'secure' flag. Setting it to true ensures the cookie is sent only over HTTPS.
Fix the error in the code to set a cookie with HttpOnly flag.
<?php setcookie('token', 'xyz', time() + 3600, '/', '', false, [1]); ?>
The seventh parameter of setcookie is the HttpOnly flag. Setting it to true helps protect the cookie from being accessed by JavaScript.
Fill both blanks to set a cookie that expires in 2 hours and is restricted to the '/account' path.
<?php setcookie('auth', 'token123', [1], [2]); ?>
The expiration time is set to 2 hours from now using time() + 7200. The path parameter restricts the cookie to the '/account' directory.
Fill all three blanks to set a cookie with name in uppercase, value from variable, and secure flag enabled.
<?php $name = 'sessionid'; $value = 'abc123'; setcookie([1], [2], time() + 3600, '/', '', [3], true); ?>
The cookie name is converted to uppercase using strtoupper($name). The value is passed as $value. The secure flag is set to true to restrict cookie to HTTPS.