filter-input

Pass a value into filter_input() using variable

六眼飞鱼酱① 提交于 2019-12-02 02:06:48
Can anyone please explain, why do I get very strange warning: filter_input() expects parameter 1 to be long, string given when executing the code, that is part of my class and which seems perfectly fine: public static function Input($type, $data, $filter = 'FILTER_SANITIZE_SPECIAL_CHARS') { $type = 'INPUT_' . $type; return filter_input($type, $data, $filter); } In case I change it to, for example: return filter_input(INPUT_POST, $data, $filter); Then the warning goes to: filter_input() expects parameter 3 to be long . Everything works just fine if I use: return filter_input(INPUT_POST, $data,

PHP's new input_filter does not read $_GET or $_POST arrays

*爱你&永不变心* 提交于 2019-11-29 01:54:35
In PHP 5.2 there was a nice security function added called "input_filter", so instead of saying: $name = $_GET['name']; you can now say: $name = filter_input (INPUT_GET, 'name', FILTER_SANITIZE_STRING); and it automatically sanitizes your string, there is also: FILTER_SANITIZE_ENCODED FILTER_SANITIZE_NUMBER_INT FILTER_SANITIZE_EMAIL FILTER_SANITIZE_URL etc. so this is a very convenient security feature to use and I want to switch over to it completely. The problem is... I often manipulate the $_GET and $_POST arrays before processing them, like this: $_GET['name'] = '(default name)'; but it

FILTER_SANITIZE vs FILTER VALIDATE, whats the difference - and which to use?

给你一囗甜甜゛ 提交于 2019-11-26 21:19:49
问题 Currently I'm making sort of calculator-like app in PHP with form as method of input. To secure input i'm using filter_input() function. As filter this function take one of elements from two groups: FILTER_SANITIZE and FILTER_VALIDATE , which one should i use to filter input from form? $number1 = trim(filter_input(INPUT_GET, 'number1', FILTER_VALIDATE_FLOAT)); or $number1 = trim(filter_input(INPUT_GET, 'number1', FILTER_SANITIZE_FLOAT)); 回答1: It depends on what you need or is suitable for