【问题标题】:setcookie(): Passing null to parameter #7 ($httponly) of type bool is deprecatedsetcookie():不推荐将 null 传递给 bool 类型的参数 #7 ($httponly)
【发布时间】:2022-01-03 08:55:28
【问题描述】:
public function csrf_set_cookie()
{
    $expire = time() + $this->_csrf_expire;
    $secure_cookie = (bool) config_item('cookie_secure');

    if ($secure_cookie && ! is_https())
    {
        return FALSE;
    }

    setcookie(
        $this->_csrf_cookie_name,
        $this->_csrf_hash,
        $expire,
        config_item('cookie_path'),
        config_item('cookie_domain'),
        $secure_cookie,
        config_item('cookie_httponly')
    );
    log_message('info', 'CSRF cookie sent');

    return $this;
}

严重性:8192

消息:setcookie():将 null 传递给类型 > bool 的参数 #7 ($httponly) 已弃用

文件名:core/Security.php

【问题讨论】:

  • 我建议不要将 null 传递给该参数。你有什么问题?该警告似乎不言自明

标签: php codeigniter cookies setcookie httponly


【解决方案1】:

正如警告所说,您不应该将 NULL 传递给 httponly 参数。如果您的配置中没有定义它,您可以使用 NULL-coalescing 来传递智能默认值。例如:

setcookie(
    $this->_csrf_cookie_name,
    $this->_csrf_hash,
    $expire,
    config_item('cookie_path'),
    config_item('cookie_domain'),
    $secure_cookie,
    config_item('cookie_httponly') ?? true 
    # Here ------------------------^
);

【讨论】:

    猜你喜欢
    • 2022-10-23
    • 2022-07-03
    • 2022-01-13
    • 2023-01-03
    • 1970-01-01
    • 2020-08-23
    • 2021-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多