Cookie.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\web;
  8. /**
  9. * Cookie represents information related with a cookie, such as [[name]], [[value]], [[domain]], etc.
  10. *
  11. * For more details and usage information on Cookie, see the [guide article on handling cookies](guide:runtime-sessions-cookies).
  12. *
  13. * @author Qiang Xue <qiang.xue@gmail.com>
  14. * @since 2.0
  15. */
  16. class Cookie extends \yii\base\Object
  17. {
  18. /**
  19. * @var string name of the cookie
  20. */
  21. public $name;
  22. /**
  23. * @var string value of the cookie
  24. */
  25. public $value = '';
  26. /**
  27. * @var string domain of the cookie
  28. */
  29. public $domain = '';
  30. /**
  31. * @var int the timestamp at which the cookie expires. This is the server timestamp.
  32. * Defaults to 0, meaning "until the browser is closed".
  33. */
  34. public $expire = 0;
  35. /**
  36. * @var string the path on the server in which the cookie will be available on. The default is '/'.
  37. */
  38. public $path = '/';
  39. /**
  40. * @var bool whether cookie should be sent via secure connection
  41. */
  42. public $secure = false;
  43. /**
  44. * @var bool whether the cookie should be accessible only through the HTTP protocol.
  45. * By setting this property to true, the cookie will not be accessible by scripting languages,
  46. * such as JavaScript, which can effectively help to reduce identity theft through XSS attacks.
  47. */
  48. public $httpOnly = true;
  49. /**
  50. * Magic method to turn a cookie object into a string without having to explicitly access [[value]].
  51. *
  52. * ```php
  53. * if (isset($request->cookies['name'])) {
  54. * $value = (string) $request->cookies['name'];
  55. * }
  56. * ```
  57. *
  58. * @return string The value of the cookie. If the value property is null, an empty string will be returned.
  59. */
  60. public function __toString()
  61. {
  62. return (string) $this->value;
  63. }
  64. }