What's wrong with using $_REQUEST[]?

后端 未结 16 1489
走了就别回头了
走了就别回头了 2020-11-22 03:53

I\'ve seen a number of posts on here saying not to use the $_REQUEST variable. I usually don\'t, but sometimes it\'s convenient. What\'s wrong with it?

16条回答
  •  抹茶落季
    2020-11-22 04:17

    The central problem is that it contains cookies, as others have said.

    In PHP 7 you can do this:

    $request = array_merge($_GET ?? [], $_POST ?? []);
    

    This avoids the cookie problem and gives you at worst an empty array and at best a merger of $_GET and $_POST with the latter taking precedence. If you are not too bothered with allowing URL injection of parameters through the query string, it's quite convenient.

提交回复
热议问题