[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Part of the Joomla Framework Input Package 4 * 5 * @copyright Copyright (C) 2005 - 2022 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE 7 */ 8 9 namespace Joomla\Input; 10 11 /** 12 * Joomla! Input Cookie Class 13 * 14 * @since 1.0 15 */ 16 class Cookie extends Input 17 { 18 /** 19 * Constructor. 20 * 21 * @param array|null $source Source data (Optional, default is $_COOKIE) 22 * @param array $options Array of configuration parameters (Optional) 23 * 24 * @since 1.0 25 */ 26 public function __construct($source = null, array $options = []) 27 { 28 $source = $source ?? $_COOKIE; 29 parent::__construct($source, $options); 30 } 31 32 /** 33 * Sets a value 34 * 35 * @param string $name Name of the value to set. 36 * @param mixed $value Value to assign to the input. 37 * @param array $options An associative array which may have any of the keys expires, path, domain, 38 * secure, httponly and samesite. The values have the same meaning as described 39 * for the parameters with the same name. The value of the samesite element 40 * should be either Lax or Strict. If any of the allowed options are not given, 41 * their default values are the same as the default values of the explicit 42 * parameters. If the samesite element is omitted, no SameSite cookie attribute 43 * is set. 44 * 45 * @return void 46 * 47 * @link https://www.ietf.org/rfc/rfc2109.txt 48 * @link https://php.net/manual/en/function.setcookie.php 49 * 50 * @since 1.0 51 * 52 * @note As of 1.4.0, the (name, value, expire, path, domain, secure, httpOnly) signature is deprecated and will not be supported 53 * when support for PHP 7.2 and earlier is dropped 54 */ 55 public function set($name, $value, $options = []) 56 { 57 // BC layer to convert old method parameters. 58 if (is_array($options) === false) 59 { 60 trigger_deprecation( 61 'joomla/input', 62 '1.4.0', 63 'The %s($name, $value, $expire, $path, $domain, $secure, $httpOnly) signature is deprecated and will not be supported once support' 64 . ' for PHP 7.2 and earlier is dropped, use the %s($name, $value, $options) signature instead', 65 __METHOD__, 66 __METHOD__ 67 ); 68 69 $argList = func_get_args(); 70 71 $options = [ 72 'expires' => $argList[2] ?? 0, 73 'path' => $argList[3] ?? '', 74 'domain' => $argList[4] ?? '', 75 'secure' => $argList[5] ?? false, 76 'httponly' => $argList[6] ?? false, 77 ]; 78 } 79 80 // Set the cookie 81 if (version_compare(PHP_VERSION, '7.3', '>=')) 82 { 83 setcookie($name, $value, $options); 84 } 85 else 86 { 87 // Using the setcookie function before php 7.3, make sure we have default values. 88 if (array_key_exists('expires', $options) === false) 89 { 90 $options['expires'] = 0; 91 } 92 93 if (array_key_exists('path', $options) === false) 94 { 95 $options['path'] = ''; 96 } 97 98 if (array_key_exists('domain', $options) === false) 99 { 100 $options['domain'] = ''; 101 } 102 103 if (array_key_exists('secure', $options) === false) 104 { 105 $options['secure'] = false; 106 } 107 108 if (array_key_exists('httponly', $options) === false) 109 { 110 $options['httponly'] = false; 111 } 112 113 setcookie($name, $value, $options['expires'], $options['path'], $options['domain'], $options['secure'], $options['httponly']); 114 } 115 116 $this->data[$name] = $value; 117 } 118 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |