httpbin - 协议调试工具
httpstatuses - 协议状态码查询
httpie - cURL-like tool for humans
Fiddler
7DLNU56W
V2EX  ›  HTTP

PHP setcookie 是否支持设置 SameSite

  •  
  •   7DLNU56W · Nov 30, 2019 · 7210 views
    This topic created in 2403 days ago, the information mentioned may be changed or developed.

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

    4 replies    2019-11-30 16:29:34 +08:00
    U7Q5tLAex2FI0o0g
        2
    U7Q5tLAex2FI0o0g  
       Nov 30, 2019
    https://www.php.net/manual/en/function.setcookie.php
    7.3.0 开始支持,详情看手册

    PS:遇事不决先查手册,查不到再问
    7DLNU56W
        3
    7DLNU56W  
    OP
       Nov 30, 2019
    是说开始支持了,但没说怎么用啊,在最上面使用的语法那里,根本没有 SameSite 选项。
    U7Q5tLAex2FI0o0g
        4
    U7Q5tLAex2FI0o0g  
       Nov 30, 2019   ❤️ 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',
    ]);
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3127 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 12:50 · PVG 20:50 · LAX 05:50 · JFK 08:50
    ♥ Do have faith in what you're doing.