4

I am trying to modify this line.

Originally, it was

$cmd = $_REQUEST["cmd"];

Then, I changed to this by reading this post a link at Stackoverflow.

$cmd = filter_input(INPUT_REQUEST, "cmd");

But, I am still getting bottom error:

Warning: filter_input(): INPUT_REQUEST is not yet implemented

When I read other article a link, it says "INPUT_REQUEST is not a valid type."

What is solution here?

Java
  • 1,208
  • 3
  • 15
  • 29

6 Answers6

8

Per the documentation (and your error message, and the answer to the SitePoint Q&A you reference), it's not a valid parameter. The documentation says:

One of INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.

There is no such thing as INPUT_REQUEST for this function.

What is solution here?

Use one of the parameters that actually exists.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
7

TL;DR If you want to use filter_input()'s filter option then choose POST, GET, or COOKIE as your request type. But there are ways to get REQUEST style behaviour.

note: GET is conventionally used for sending details of a request for retrieving data, while POST is used for submitting data to be stored on the server.

You have a few options:

Indeed, so far (as of PHP 7.2) only INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV have been implemented. But you can still get INPUT_REQUEST style behaviour, or other options might actually fulfill your needs.

Implement INPUT_REQUEST Yourself: (I don't recommend this) you can use INPUT_GET, INPUT_POST and INPUT_COOKIE to implement the behaviour you would expect from the currently non-extant INPUT_REQUEST by running one, and if that didn't get anything running the next and so on, as follows.

`$test_filter = filter_input(INPUT_COOKIE, 'test') ?? filter_input(INPUT_POST, 'test') ?? filter_input(INPUT_GET, 'test');`

Use INPUT_GET or INPUT_POST: if you know which of PUSH or GET will be used to send the request then use the corresponding option. Data sent in the query string of the url will be retrieved using INPUT_GET for example.

Suppress the Superglobal Warning: you can choose which warnings netbeans shows you by going to Windows: Tools -> Options -> Editor -> Hints Mac: NetBeans -> Preferences -> Editor -> Hints and deselecting Superglobals or whatever subset of that you don't want.

Final Note: filter_input() has a third argument that is the actual filter part; if you're using filter_input anyway then you might as well actually use the filter. If you omit the argument then:

If omitted, FILTER_DEFAULT will be used, which is equivalent to FILTER_UNSAFE_RAW. This will result in no filtering taking place by default.

timeSmith
  • 553
  • 1
  • 8
  • 16
  • Thanks. This is not the accepted answer but the description is much better and it also explains the question of @Java in the first comment of the accepted answer. – Rene May 05 '20 at 07:10
2

You can use filter_var() if you still need to access $_REQUESTS in a similar manner.

There are a couple differences you need to be aware of though.

filter_var()

  • Returns "" (empty string).
  • (Recommended) Has an isset() wrap.

filter_input()

  • Returns Null.

Example

$cmd = '';
if ( isset( $_REQUEST["cmd"] ) ) {
    $cmd = filter_var( $_REQUEST["cmd"], FILTER_SANITIZE_STRING );
}
EkoJR
  • 1,223
  • 12
  • 16
1

Please note that according to this ticket: https://bugs.php.net/bug.php?id=54672, INPUT_REQUEST will never be implemented.

INPUT_REQUEST and INPUT_SESSION have been removed altogether in PHP 8.0

Ankit
  • 235
  • 1
  • 3
  • 17
1

If what you want achieve is to filter both POST and GET values using filter_input, a good way could be this one:

$cmd = filter_input(INPUT_POST, "cmd");
if ($cmd){
    $cmd = filter_input(INPUT_GET, "cmd");
}

you can even do something more accurate knowing that the return values of filter_input are:

  • false: if the filter fails
  • null: if the var_name variable is not set
  • the variable itself: if everything is ok
Philbert
  • 71
  • 3
1

Although the answer is already accepted, here is another solution that I use when I do not know or POST or GET is used.

function getRequestValue($fieldName, $filter = FILTER_DEFAULT, $options = 0)
{
    if (filter_input(INPUT_SERVER, "REQUEST_METHOD") == "POST") {
        return filter_input(INPUT_POST, $fieldName, $filter, $options);
    } else {
        return filter_input(INPUT_GET, $fieldName, $filter, $options);
    }
}

Use it like this:

$cmd = getRequestValue("cmd");

Additional optionals are similar to https://www.php.net/manual/de/function.filter-input.php

Marco
  • 3,470
  • 4
  • 23
  • 35