wp/wp-includes/class-wp-http-cookie.php
changeset 19 3d72ae0968f4
parent 16 a86126ab1dd4
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    22 
    22 
    23 	/**
    23 	/**
    24 	 * Cookie name.
    24 	 * Cookie name.
    25 	 *
    25 	 *
    26 	 * @since 2.8.0
    26 	 * @since 2.8.0
       
    27 	 *
    27 	 * @var string
    28 	 * @var string
    28 	 */
    29 	 */
    29 	public $name;
    30 	public $name;
    30 
    31 
    31 	/**
    32 	/**
    32 	 * Cookie value.
    33 	 * Cookie value.
    33 	 *
    34 	 *
    34 	 * @since 2.8.0
    35 	 * @since 2.8.0
       
    36 	 *
    35 	 * @var string
    37 	 * @var string
    36 	 */
    38 	 */
    37 	public $value;
    39 	public $value;
    38 
    40 
    39 	/**
    41 	/**
    40 	 * When the cookie expires. Unix timestamp or formatted date.
    42 	 * When the cookie expires. Unix timestamp or formatted date.
    41 	 *
    43 	 *
    42 	 * @since 2.8.0
    44 	 * @since 2.8.0
       
    45 	 *
    43 	 * @var string|int|null
    46 	 * @var string|int|null
    44 	 */
    47 	 */
    45 	public $expires;
    48 	public $expires;
    46 
    49 
    47 	/**
    50 	/**
    48 	 * Cookie URL path.
    51 	 * Cookie URL path.
    49 	 *
    52 	 *
    50 	 * @since 2.8.0
    53 	 * @since 2.8.0
       
    54 	 *
    51 	 * @var string
    55 	 * @var string
    52 	 */
    56 	 */
    53 	public $path;
    57 	public $path;
    54 
    58 
    55 	/**
    59 	/**
    56 	 * Cookie Domain.
    60 	 * Cookie Domain.
    57 	 *
    61 	 *
    58 	 * @since 2.8.0
    62 	 * @since 2.8.0
       
    63 	 *
    59 	 * @var string
    64 	 * @var string
    60 	 */
    65 	 */
    61 	public $domain;
    66 	public $domain;
    62 
    67 
    63 	/**
    68 	/**
       
    69 	 * Cookie port or comma-separated list of ports.
       
    70 	 *
       
    71 	 * @since 2.8.0
       
    72 	 *
       
    73 	 * @var int|string
       
    74 	 */
       
    75 	public $port;
       
    76 
       
    77 	/**
    64 	 * host-only flag.
    78 	 * host-only flag.
    65 	 *
    79 	 *
    66 	 * @since 5.2.0
    80 	 * @since 5.2.0
       
    81 	 *
    67 	 * @var bool
    82 	 * @var bool
    68 	 */
    83 	 */
    69 	public $host_only;
    84 	public $host_only;
    70 
    85 
    71 	/**
    86 	/**
    83 	 *     @type string          $name      Cookie name.
    98 	 *     @type string          $name      Cookie name.
    84 	 *     @type mixed           $value     Value. Should NOT already be urlencoded.
    99 	 *     @type mixed           $value     Value. Should NOT already be urlencoded.
    85 	 *     @type string|int|null $expires   Optional. Unix timestamp or formatted date. Default null.
   100 	 *     @type string|int|null $expires   Optional. Unix timestamp or formatted date. Default null.
    86 	 *     @type string          $path      Optional. Path. Default '/'.
   101 	 *     @type string          $path      Optional. Path. Default '/'.
    87 	 *     @type string          $domain    Optional. Domain. Default host of parsed $requested_url.
   102 	 *     @type string          $domain    Optional. Domain. Default host of parsed $requested_url.
    88 	 *     @type int             $port      Optional. Port. Default null.
   103 	 *     @type int|string      $port      Optional. Port or comma-separated list of ports. Default null.
    89 	 *     @type bool            $host_only Optional. host-only storage flag. Default true.
   104 	 *     @type bool            $host_only Optional. host-only storage flag. Default true.
    90 	 * }
   105 	 * }
    91 	 * @param string       $requested_url The URL which the cookie was set on, used for default $domain
   106 	 * @param string       $requested_url The URL which the cookie was set on, used for default $domain
    92 	 *                                    and $port values.
   107 	 *                                    and $port values.
    93 	 */
   108 	 */
    94 	public function __construct( $data, $requested_url = '' ) {
   109 	public function __construct( $data, $requested_url = '' ) {
    95 		if ( $requested_url ) {
   110 		if ( $requested_url ) {
    96 			$arrURL = parse_url( $requested_url );
   111 			$parsed_url = parse_url( $requested_url );
    97 		}
   112 		}
    98 		if ( isset( $arrURL['host'] ) ) {
   113 		if ( isset( $parsed_url['host'] ) ) {
    99 			$this->domain = $arrURL['host'];
   114 			$this->domain = $parsed_url['host'];
   100 		}
   115 		}
   101 		$this->path = isset( $arrURL['path'] ) ? $arrURL['path'] : '/';
   116 		$this->path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '/';
   102 		if ( '/' !== substr( $this->path, -1 ) ) {
   117 		if ( '/' !== substr( $this->path, -1 ) ) {
   103 			$this->path = dirname( $this->path ) . '/';
   118 			$this->path = dirname( $this->path ) . '/';
   104 		}
   119 		}
   105 
   120 
   106 		if ( is_string( $data ) ) {
   121 		if ( is_string( $data ) ) {
   185 			$domain .= '.local';
   200 			$domain .= '.local';
   186 		}
   201 		}
   187 
   202 
   188 		// Host - very basic check that the request URL ends with the domain restriction (minus leading dot).
   203 		// Host - very basic check that the request URL ends with the domain restriction (minus leading dot).
   189 		$domain = ( '.' === substr( $domain, 0, 1 ) ) ? substr( $domain, 1 ) : $domain;
   204 		$domain = ( '.' === substr( $domain, 0, 1 ) ) ? substr( $domain, 1 ) : $domain;
   190 		if ( substr( $url['host'], -strlen( $domain ) ) != $domain ) {
   205 		if ( substr( $url['host'], -strlen( $domain ) ) !== $domain ) {
   191 			return false;
   206 			return false;
   192 		}
   207 		}
   193 
   208 
   194 		// Port - supports "port-lists" in the format: "80,8000,8080".
   209 		// Port - supports "port-lists" in the format: "80,8000,8080".
   195 		if ( ! empty( $port ) && ! in_array( $url['port'], array_map( 'intval', explode( ',', $port ) ), true ) ) {
   210 		if ( ! empty( $port ) && ! in_array( $url['port'], array_map( 'intval', explode( ',', $port ) ), true ) ) {
   196 			return false;
   211 			return false;
   197 		}
   212 		}
   198 
   213 
   199 		// Path - request path must start with path restriction.
   214 		// Path - request path must start with path restriction.
   200 		if ( substr( $url['path'], 0, strlen( $path ) ) != $path ) {
   215 		if ( substr( $url['path'], 0, strlen( $path ) ) !== $path ) {
   201 			return false;
   216 			return false;
   202 		}
   217 		}
   203 
   218 
   204 		return true;
   219 		return true;
   205 	}
   220 	}