php - setcookie() 期望参数 3 是整数,给定数组

标签 php cookies

我收到此 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/

相关文章:

javascript - 使用 PHP 和 AngularJS 加载更多评论

php - Ajax/jQuery 使用数组填充 Laravel 中的表

php - PDO 中的 "SELECT :parameter FROM .."

php - 如何使用 Phalcon 框架加入 2 个集合?

php - 间接修改重载属性 App\Category::$thesizes 没有效果

javascript - 在for循环中设置cookie

javascript - Cookie 并不总是有效

javascript - 写入document.cookie需要多长时间

ruby-on-rails - Rails cookie 中 request_method 值的用途是什么?

jquery - 如何检查 cookie 是否已使用 jQuery 设置?