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

后端 未结 15 2224
小鲜肉
小鲜肉 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:53

    There are certain security concerns involved as a hacker can set a cookie that will override a $_POST or $_GET value. If you handle sensitive data, I would not recommend using $_REQUEST. – Xandor

    you can't be used $_GET alternative of $_POST on some case.

    When ??

    • when you want to upload a file.
    • when you don't won't to show a data in url.

    GET also has limits on the amount of information to send. The limitation is about 2000 characters.

    Other thing's there are few case when you can't retrieve a data using $_POST

    When ?

    • when data is passed in URL.

    For Rest Service

    `GET` - Provides a read only access to a resource.
    
    `PUT` - Used to create a new resource.
    

    there is nothing be wrong to use $_REQUEST.

    But the way to do that is to check $_SERVER['REQUEST_METHOD'] explicitly, not rely on $_POST being empty for a GET.

提交回复
热议问题