Skip to content
PHP Logo

What potential issues can arise when upgrading a PHP script from version 5.6 to 7.3, specifically related to setting cookies?

When upgrading a PHP script from version 5.6 to 7.3, one potential issue related to setting cookies is the change in how the `setcookie()` function handles the expiration time parameter. In PHP 7.3, the expiration time must be specified as a Unix timestamp or using the `time()` function. To solve this issue, make sure to convert any expiration time values to Unix timestamps before passing them to the `setcookie()` function.

php
// Convert expiration time to Unix timestamp
$expiration = time() + 3600; // set cookie to expire in 1 hour

// Set cookie with updated expiration time
setcookie("cookie_name", "cookie_value", $expiration, "/");