我收到此 PHP 错误:
PHP Warning: setcookie() expects parameter 3 to be integer, array given
使用此代码:
$setResult = setcookie(
'visitorId',
"{$newIdForNewVisitor}",
[
'httponly' => true,
'expires' => time() + (50 * 365 * 24 * 60 * 60)
]
);
但是在 the
setcookie
documentation 的第二个例子中,我看到参数 3 上的 options 参数可以采用关联数组: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.
这里犯了什么错误?
最佳答案
您可能需要检查您正在运行的 PHP 版本。
setcookie 函数的替代签名仅在 PHP 7.3.0 版中添加。
关于php - setcookie() 期望参数 3 是整数,给定数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57401836/