-
Notifications
You must be signed in to change notification settings - Fork 8
/
filter.php
497 lines (437 loc) · 14.2 KB
/
filter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
<?php
// Start of filter v.7.0.4-7ubuntu2
/**
* (PHP 5 >= 5.2.0, PHP 7)<br/>
* Gets a specific external variable by name and optionally filters it
* @link http://php.net/manual/en/function.filter-input.php
* @param int $type <p>
* One of <b>INPUT_GET</b>, <b>INPUT_POST</b>,
* <b>INPUT_COOKIE</b>, <b>INPUT_SERVER</b>, or
* <b>INPUT_ENV</b>.
* </p>
* @param string $variable_name <p>
* Name of a variable to get.
* </p>
* @param int $filter [optional]
* @param mixed $options [optional] <p>
* Associative array of options or bitwise disjunction of flags. If filter
* accepts options, flags can be provided in "flags" field of array.
* </p>
* @return mixed Value of the requested variable on success, <b>FALSE</b> if the filter fails,
* or <b>NULL</b> if the <i>variable_name</i> variable is not set.
* If the flag <b>FILTER_NULL_ON_FAILURE</b> is used, it
* returns <b>FALSE</b> if the variable is not set and <b>NULL</b> if the filter fails.
*/
function filter_input(int $type, string $variable_name, int $filter = FILTER_DEFAULT, $options = null) {}
/**
* (PHP 5 >= 5.2.0, PHP 7)<br/>
* Filters a variable with a specified filter
* @link http://php.net/manual/en/function.filter-var.php
* @param mixed $variable <p>
* Value to filter.
* </p>
* @param int $filter [optional]
* @param mixed $options [optional] <p>
* Associative array of options or bitwise disjunction of flags. If filter
* accepts options, flags can be provided in "flags" field of array. For
* the "callback" filter, callable type should be passed. The
* callback must accept one argument, the value to be filtered, and return
* the value after filtering/sanitizing it.
* </p>
* <p>
* <code>
* // for filters that accept options, use this format
* $options = array(
* 'options' => array(
* 'default' => 3, // value to return if the filter fails
* // other options here
* 'min_range' => 0
* ),
* 'flags' => FILTER_FLAG_ALLOW_OCTAL,
* );
* $var = filter_var('0755', FILTER_VALIDATE_INT, $options);
* // for filter that only accept flags, you can pass them directly
* $var = filter_var('oops', FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
* // for filter that only accept flags, you can also pass as an array
* $var = filter_var('oops', FILTER_VALIDATE_BOOLEAN,
* array('flags' => FILTER_NULL_ON_FAILURE));
* // callback validate filter
* function foo($value)
* {
* // Expected format: Surname, GivenNames
* if (strpos($value, ", ") === false) return false;
* list($surname, $givennames) = explode(", ", $value, 2);
* $empty = (empty($surname) || empty($givennames));
* $notstrings = (!is_string($surname) || !is_string($givennames));
* if ($empty || $notstrings) {
* return false;
* } else {
* return $value;
* }
* }
* $var = filter_var('Doe, Jane Sue', FILTER_CALLBACK, array('options' => 'foo'));
* </code>
* </p>
* @return mixed the filtered data, or <b>FALSE</b> if the filter fails.
*/
function filter_var($variable, int $filter = FILTER_DEFAULT, $options = null) {}
/**
* (PHP 5 >= 5.2.0, PHP 7)<br/>
* Gets external variables and optionally filters them
* @link http://php.net/manual/en/function.filter-input-array.php
* @param int $type <p>
* One of <b>INPUT_GET</b>, <b>INPUT_POST</b>,
* <b>INPUT_COOKIE</b>, <b>INPUT_SERVER</b>, or
* <b>INPUT_ENV</b>.
* </p>
* @param mixed $definition [optional] <p>
* An array defining the arguments. A valid key is a string
* containing a variable name and a valid value is either a filter type, or an array
* optionally specifying the filter, flags and options. If the value is an
* array, valid keys are filter which specifies the
* filter type,
* flags which specifies any flags that apply to the
* filter, and options which specifies any options that
* apply to the filter. See the example below for a better understanding.
* </p>
* <p>
* This parameter can be also an integer holding a filter constant. Then all values in the
* input array are filtered by this filter.
* </p>
* @param bool $add_empty [optional] <p>
* Add missing keys as <b>NULL</b> to the return value.
* </p>
* @return mixed An array containing the values of the requested variables on success, or <b>FALSE</b>
* on failure. An array value will be <b>FALSE</b> if the filter fails, or <b>NULL</b> if
* the variable is not set. Or if the flag <b>FILTER_NULL_ON_FAILURE</b>
* is used, it returns <b>FALSE</b> if the variable is not set and <b>NULL</b> if the filter
* fails.
*/
function filter_input_array(int $type, $definition = null, bool $add_empty = true) {}
/**
* (PHP 5 >= 5.2.0, PHP 7)<br/>
* Gets multiple variables and optionally filters them
* @link http://php.net/manual/en/function.filter-var-array.php
* @param array $data <p>
* An array with string keys containing the data to filter.
* </p>
* @param mixed $definition [optional] <p>
* An array defining the arguments. A valid key is a string
* containing a variable name and a valid value is either a
* filter type, or an
* array optionally specifying the filter, flags and options.
* If the value is an array, valid keys are filter
* which specifies the filter type,
* flags which specifies any flags that apply to the
* filter, and options which specifies any options that
* apply to the filter. See the example below for a better understanding.
* </p>
* <p>
* This parameter can be also an integer holding a filter constant. Then all values in the
* input array are filtered by this filter.
* </p>
* @param bool $add_empty [optional] <p>
* Add missing keys as <b>NULL</b> to the return value.
* </p>
* @return mixed An array containing the values of the requested variables on success, or <b>FALSE</b>
* on failure. An array value will be <b>FALSE</b> if the filter fails, or <b>NULL</b> if
* the variable is not set.
*/
function filter_var_array(array $data, $definition = null, bool $add_empty = true) {}
/**
* (PHP 5 >= 5.2.0, PHP 7)<br/>
* Returns a list of all supported filters
* @link http://php.net/manual/en/function.filter-list.php
* @return array an array of names of all supported filters, empty array if there
* are no such filters. Indexes of this array are not filter IDs, they can be
* obtained with <b>filter_id</b> from a name instead.
*/
function filter_list(): array {}
/**
* (PHP 5 >= 5.2.0, PHP 7)<br/>
* Checks if variable of specified type exists
* @link http://php.net/manual/en/function.filter-has-var.php
* @param int $type <p>
* One of <b>INPUT_GET</b>, <b>INPUT_POST</b>,
* <b>INPUT_COOKIE</b>, <b>INPUT_SERVER</b>, or
* <b>INPUT_ENV</b>.
* </p>
* @param string $variable_name <p>
* Name of a variable to check.
* </p>
* @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure.
*/
function filter_has_var(int $type, string $variable_name): bool {}
/**
* (PHP 5 >= 5.2.0, PHP 7)<br/>
* Returns the filter ID belonging to a named filter
* @link http://php.net/manual/en/function.filter-id.php
* @param string $filtername <p>
* Name of a filter to get.
* </p>
* @return int ID of a filter on success or <b>FALSE</b> if filter doesn't exist.
*/
function filter_id(string $filtername): int {}
/**
* POST variables.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('INPUT_POST', 0);
/**
* GET variables.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('INPUT_GET', 1);
/**
* COOKIE variables.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('INPUT_COOKIE', 2);
/**
* ENV variables.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('INPUT_ENV', 4);
/**
* SERVER variables.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('INPUT_SERVER', 5);
/**
* SESSION variables.
* (not implemented yet)
* @link http://php.net/manual/en/filter.constants.php
*/
define ('INPUT_SESSION', 6);
/**
* REQUEST variables.
* (not implemented yet)
* @link http://php.net/manual/en/filter.constants.php
*/
define ('INPUT_REQUEST', 99);
/**
* No flags.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_NONE', 0);
/**
* Flag used to require scalar as input
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_REQUIRE_SCALAR', 33554432);
/**
* Require an array as input.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_REQUIRE_ARRAY', 16777216);
/**
* Always returns an array.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FORCE_ARRAY', 67108864);
/**
* Use NULL instead of FALSE on failure.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_NULL_ON_FAILURE', 134217728);
/**
* ID of "int" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_VALIDATE_INT', 257);
/**
* ID of "boolean" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_VALIDATE_BOOLEAN', 258);
/**
* ID of "float" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_VALIDATE_FLOAT', 259);
/**
* ID of "validate_regexp" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_VALIDATE_REGEXP', 272);
define ('FILTER_VALIDATE_DOMAIN', 277);
/**
* ID of "validate_url" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_VALIDATE_URL', 273);
/**
* ID of "validate_email" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_VALIDATE_EMAIL', 274);
/**
* ID of "validate_ip" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_VALIDATE_IP', 275);
/**
* ID of "validate_mac_address" filter.
* (Available as of PHP 5.5.0)
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_VALIDATE_MAC', 276);
/**
* ID of default ("unsafe_raw") filter. This is equivalent to
* <b>FILTER_UNSAFE_RAW</b>.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_DEFAULT', 516);
/**
* ID of "unsafe_raw" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_UNSAFE_RAW', 516);
/**
* ID of "string" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_SANITIZE_STRING', 513);
/**
* ID of "stripped" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_SANITIZE_STRIPPED', 513);
/**
* ID of "encoded" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_SANITIZE_ENCODED', 514);
/**
* ID of "special_chars" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_SANITIZE_SPECIAL_CHARS', 515);
define ('FILTER_SANITIZE_FULL_SPECIAL_CHARS', 522);
/**
* ID of "email" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_SANITIZE_EMAIL', 517);
/**
* ID of "url" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_SANITIZE_URL', 518);
/**
* ID of "number_int" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_SANITIZE_NUMBER_INT', 519);
/**
* ID of "number_float" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_SANITIZE_NUMBER_FLOAT', 520);
/**
* ID of "magic_quotes" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_SANITIZE_MAGIC_QUOTES', 521);
/**
* ID of "callback" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_CALLBACK', 1024);
/**
* Allow octal notation (0[0-7]+) in "int" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_ALLOW_OCTAL', 1);
/**
* Allow hex notation (0x[0-9a-fA-F]+) in "int" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_ALLOW_HEX', 2);
/**
* Strip characters with ASCII value less than 32.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_STRIP_LOW', 4);
/**
* Strip characters with ASCII value greater than 127.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_STRIP_HIGH', 8);
define ('FILTER_FLAG_STRIP_BACKTICK', 512);
/**
* Encode characters with ASCII value less than 32.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_ENCODE_LOW', 16);
/**
* Encode characters with ASCII value greater than 127.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_ENCODE_HIGH', 32);
/**
* Encode &#38;.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_ENCODE_AMP', 64);
/**
* Don't encode ' and ".
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_NO_ENCODE_QUOTES', 128);
/**
* (No use for now.)
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_EMPTY_STRING_NULL', 256);
/**
* Allow fractional part in "number_float" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_ALLOW_FRACTION', 4096);
/**
* Allow thousand separator (,) in "number_float" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_ALLOW_THOUSAND', 8192);
/**
* Allow scientific notation (e, E) in
* "number_float" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_ALLOW_SCIENTIFIC', 16384);
define ('FILTER_FLAG_SCHEME_REQUIRED', 65536);
define ('FILTER_FLAG_HOST_REQUIRED', 131072);
/**
* Require path in "validate_url" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_PATH_REQUIRED', 262144);
/**
* Require query in "validate_url" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_QUERY_REQUIRED', 524288);
/**
* Allow only IPv4 address in "validate_ip" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_IPV4', 1048576);
/**
* Allow only IPv6 address in "validate_ip" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_IPV6', 2097152);
/**
* Deny reserved addresses in "validate_ip" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_NO_RES_RANGE', 4194304);
/**
* Deny private addresses in "validate_ip" filter.
* @link http://php.net/manual/en/filter.constants.php
*/
define ('FILTER_FLAG_NO_PRIV_RANGE', 8388608);
define ('FILTER_FLAG_HOSTNAME', 1048576);
// End of filter v.7.0.4-7ubuntu2
?>