Reputation: 4292
I am getting this PHP error:
PHP Warning: setcookie() expects parameter 3 to be integer, array given
With this code:
$setResult = setcookie(
'visitorId',
"{$newIdForNewVisitor}",
[
'httponly' => true,
'expires' => time() + (50 * 365 * 24 * 60 * 60)
]
);
But on the 2nd example of the setcookie
documentation, I see that the options parameter on argument 3 can take an associative array:
An associative array which may have any of the keys expires, path, domain, secure, httponly and samesite. The values have the same meaning as described for the parameters with the same name. The value of the samesite element should be either Lax or Strict. If any of the allowed options are not given, their default values are the same as the default values of the explicit parameters. If the samesite element is omitted, no SameSite cookie attribute is set.
What mistake is being made here?
Upvotes: 5
Views: 6652
Reputation: 31
You may need to check which version of PHP you are running. The alternative signature of the setcookie function was only added in PHP version 7.3.0.
Upvotes: 3