/libraries/joomla/input/cookie.php

https://bitbucket.org/pastor399/newcastleunifc · PHP · 91 lines · 23 code · 6 blank · 62 comment · 1 complexity · f4ec1e2e6dfcc06c8d505e11dc4963be MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage Input
  5. *
  6. * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. defined('JPATH_PLATFORM') or die;
  10. /**
  11. * Joomla! Input Cookie Class
  12. *
  13. * @package Joomla.Platform
  14. * @subpackage Input
  15. * @since 11.1
  16. */
  17. class JInputCookie extends JInput
  18. {
  19. /**
  20. * Constructor.
  21. *
  22. * @param array $source Ignored.
  23. * @param array $options Array of configuration parameters (Optional)
  24. *
  25. * @since 11.1
  26. */
  27. public function __construct(array $source = null, array $options = array())
  28. {
  29. if (isset($options['filter']))
  30. {
  31. $this->filter = $options['filter'];
  32. }
  33. else
  34. {
  35. $this->filter = JFilterInput::getInstance();
  36. }
  37. // Set the data source.
  38. $this->data = & $_COOKIE;
  39. // Set the options for the class.
  40. $this->options = $options;
  41. }
  42. /**
  43. * Sets a value
  44. *
  45. * @param string $name Name of the value to set.
  46. * @param mixed $value Value to assign to the input.
  47. * @param integer $expire The time the cookie expires. This is a Unix timestamp so is in number
  48. * of seconds since the epoch. In other words, you'll most likely set this
  49. * with the time() function plus the number of seconds before you want it
  50. * to expire. Or you might use mktime(). time()+60*60*24*30 will set the
  51. * cookie to expire in 30 days. If set to 0, or omitted, the cookie will
  52. * expire at the end of the session (when the browser closes).
  53. * @param string $path The path on the server in which the cookie will be available on. If set
  54. * to '/', the cookie will be available within the entire domain. If set to
  55. * '/foo/', the cookie will only be available within the /foo/ directory and
  56. * all sub-directories such as /foo/bar/ of domain. The default value is the
  57. * current directory that the cookie is being set in.
  58. * @param string $domain The domain that the cookie is available to. To make the cookie available
  59. * on all subdomains of example.com (including example.com itself) then you'd
  60. * set it to '.example.com'. Although some browsers will accept cookies without
  61. * the initial ., RFC 2109 requires it to be included. Setting the domain to
  62. * 'www.example.com' or '.www.example.com' will make the cookie only available
  63. * in the www subdomain.
  64. * @param boolean $secure Indicates that the cookie should only be transmitted over a secure HTTPS
  65. * connection from the client. When set to TRUE, the cookie will only be set
  66. * if a secure connection exists. On the server-side, it's on the programmer
  67. * to send this kind of cookie only on secure connection (e.g. with respect
  68. * to $_SERVER["HTTPS"]).
  69. * @param boolean $httpOnly When TRUE the cookie will be made accessible only through the HTTP protocol.
  70. * This means that the cookie won't be accessible by scripting languages, such
  71. * as JavaScript. This setting can effectively help to reduce identity theft
  72. * through XSS attacks (although it is not supported by all browsers).
  73. *
  74. * @return void
  75. *
  76. * @link http://www.ietf.org/rfc/rfc2109.txt
  77. * @see setcookie()
  78. * @since 11.1
  79. */
  80. public function set($name, $value, $expire = 0, $path = '', $domain = '', $secure = false, $httpOnly = false)
  81. {
  82. setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
  83. $this->data[$name] = $value;
  84. }
  85. }