V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
httpbin - 协议调试工具
httpstatuses - 协议状态码查询
httpie - cURL-like tool for humans
Fiddler
7DLNU56W
V2EX  ›  HTTP

PHP setcookie 是否支持设置 SameSite

  •  
  •   7DLNU56W · 2019-11-30 13:39:51 +08:00 · 6226 次点击
    这是一个创建于 1580 天前的主题,其中的信息可能已经有所发展或是发生改变。

    现在 setcookie Header 里面多了一个 SameSite,但 php 里的 setcookie 怎么设置这个值呢?

    4 条回复    2019-11-30 16:29:34 +08:00
    qiayue
        1
    qiayue  
       2019-11-30 13:44:47 +08:00
    littleylv
        2
    littleylv  
       2019-11-30 13:48:08 +08:00
    https://www.php.net/manual/en/function.setcookie.php
    7.3.0 开始支持,详情看手册

    PS:遇事不决先查手册,查不到再问
    7DLNU56W
        3
    7DLNU56W  
    OP
       2019-11-30 15:51:22 +08:00
    是说开始支持了,但没说怎么用啊,在最上面使用的语法那里,根本没有 SameSite 选项。
    littleylv
        4
    littleylv  
       2019-11-30 16:29:34 +08:00   ❤️ 1
    @7DLNU56W #2 你不会浏览器 control+F 搜索一下“ SameSite”?

    setcookie ( string $name [, string $value = "" [, int $expires = 0 [, string $path = "" [, string $domain = "" [, bool $secure = FALSE [, bool $httponly = FALSE ]]]]]] ) : bool
    setcookie ( string $name [, string $value = "" [, array $options = [] ]] ) : bool

    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.


    那当然是
    setcookie('key', 'val', [
    'domain' => 'xx',
    'expires' => 'yy',
    'samesite' => 'Lax',
    ]);
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1319 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 23:31 · PVG 07:31 · LAX 16:31 · JFK 19:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.