Search code examples
phpsecuritysql-injection

php catch post proper way


In server side php how to catch post from view then do business logic, should I use below example 2- write down every post key, if use 1- is there any secure problem could happen?

1-

if (isset($_POST)) {
  // do something use $_POST['..']
} else {
  // denied
}

2-

if (isset($_POST['name']) && isset($_POST['password']) && isset($_POST['password_confirm']) ) {
  // do something
} else {
  // denied
}

3-

if ($_POST) {
}

Solution

  • Just make sure the function(s)/method(s) that are using these post values are protected against SQL Injection, and that they do basic check on their input arguments, and everything should be fine.