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 } |