Among $_REQUEST, $_GET and $_POST which one is the fastest?

后端 未结 15 2506
小鲜肉
小鲜肉 2020-11-22 05:04

Which of these code will be faster?

$temp = $_REQUEST[\'s\'];

or

if (isset($_GET[\'s\'])) {
  $temp = $_GET[\'s\'];
}
else          


        
15条回答
  •  死守一世寂寞
    2020-11-22 05:50

    I only ever use _GET or _POST. I prefer to have control.

    What I don't like about either code fragment in the OP is that they discard the information on which HTTP method was used. And that information is important for input sanitization.

    For example, if a script accepts data from a form that's going to be entered into the DB then the form had better use POST (use GET only for idempotent actions). But if the script receives the input data via the GET method then it should (normally) be rejected. For me, such a situation might warrant writing a security violation to the error log since it's a sign somebody is trying something on.

    With either code fragment in the OP, this sanitization wouldn't be possible.

提交回复
热议问题