Cookie.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace Config;
  3. use CodeIgniter\Config\BaseConfig;
  4. use DateTimeInterface;
  5. class Cookie extends BaseConfig
  6. {
  7. /**
  8. * --------------------------------------------------------------------------
  9. * Cookie Prefix
  10. * --------------------------------------------------------------------------
  11. *
  12. * Set a cookie name prefix if you need to avoid collisions.
  13. */
  14. public string $prefix = '';
  15. /**
  16. * --------------------------------------------------------------------------
  17. * Cookie Expires Timestamp
  18. * --------------------------------------------------------------------------
  19. *
  20. * Default expires timestamp for cookies. Setting this to `0` will mean the
  21. * cookie will not have the `Expires` attribute and will behave as a session
  22. * cookie.
  23. *
  24. * @var DateTimeInterface|int|string
  25. */
  26. public $expires = 0;
  27. /**
  28. * --------------------------------------------------------------------------
  29. * Cookie Path
  30. * --------------------------------------------------------------------------
  31. *
  32. * Typically will be a forward slash.
  33. */
  34. public string $path = '/';
  35. /**
  36. * --------------------------------------------------------------------------
  37. * Cookie Domain
  38. * --------------------------------------------------------------------------
  39. *
  40. * Set to `.your-domain.com` for site-wide cookies.
  41. */
  42. public string $domain = '';
  43. /**
  44. * --------------------------------------------------------------------------
  45. * Cookie Secure
  46. * --------------------------------------------------------------------------
  47. *
  48. * Cookie will only be set if a secure HTTPS connection exists.
  49. */
  50. public bool $secure = false;
  51. /**
  52. * --------------------------------------------------------------------------
  53. * Cookie HTTPOnly
  54. * --------------------------------------------------------------------------
  55. *
  56. * Cookie will only be accessible via HTTP(S) (no JavaScript).
  57. */
  58. public bool $httponly = true;
  59. /**
  60. * --------------------------------------------------------------------------
  61. * Cookie SameSite
  62. * --------------------------------------------------------------------------
  63. *
  64. * Configure cookie SameSite setting. Allowed values are:
  65. * - None
  66. * - Lax
  67. * - Strict
  68. * - ''
  69. *
  70. * Alternatively, you can use the constant names:
  71. * - `Cookie::SAMESITE_NONE`
  72. * - `Cookie::SAMESITE_LAX`
  73. * - `Cookie::SAMESITE_STRICT`
  74. *
  75. * Defaults to `Lax` for compatibility with modern browsers. Setting `''`
  76. * (empty string) means default SameSite attribute set by browsers (`Lax`)
  77. * will be set on cookies. If set to `None`, `$secure` must also be set.
  78. *
  79. * @phpstan-var 'None'|'Lax'|'Strict'|''
  80. */
  81. public string $samesite = 'Lax';
  82. /**
  83. * --------------------------------------------------------------------------
  84. * Cookie Raw
  85. * --------------------------------------------------------------------------
  86. *
  87. * This flag allows setting a "raw" cookie, i.e., its name and value are
  88. * not URL encoded using `rawurlencode()`.
  89. *
  90. * If this is set to `true`, cookie names should be compliant of RFC 2616's
  91. * list of allowed characters.
  92. *
  93. * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes
  94. * @see https://tools.ietf.org/html/rfc2616#section-2.2
  95. */
  96. public bool $raw = false;
  97. }