php $_REQUEST, $_GET, $_POST
Blogs20102010-11-12
When we process submit form, how to accept the input request? We have 3 choices: $_REQUEST, $_GET, $_POST. Whatâs the difference between $_REQUEST and the other 2 ?
$_REQUEST contains: $_GET, $_POST request, as well as $_COOKIE variables.
The following is a real case which occurs bugs, For the html form:
- <form action=âprocess\submit.phpâ, method=âGETâ>âŠ_
Suppose we have 2 import pairs: [âuserâ]=âtest_userâ, [âpassâ]=âtest_passâ.
If using $_GET or $_POST, we accurately get what we are expecting:
- and user = âtest\userâ and pass = âtest_passâ;_
However, if for better compatibility of changing formâs method between âGETâ and âPOSTâ, we use $_REQUEST to hold all the possibility, like:
- foreach ($\REQUEST as $key => $value) {
- Â Â $hash[$key] = trim($value);
- Â Â $condition = â and $key=ââ . $trim($value) . ââ â;
- }_
Because $_REQUEST=$_GET/$_POST + $_COOKIE, unanticipated variables are imported, here is some security holes and vogue bugs.
- and user=âtest\userâ and pass=âtest_passâ and cookie_key1=âcookie_value1â and cookie_key2=âcookie_value2â âŠ_
This is not exactly what we want.
So, if you are sure which request are input (method=âgetâ or method=âpostâ), use it directly ($_GET, or $_POST) instead of vague $_REQUEST.
In other words, avoid to use $_REQUEST, this max avoid bugs and security holes.
