I've already seen good posts about php://input vs $_POST, but I'm still confused if I need to check for both. Or just check for php://input. Any thoughts?
Is what I'm doing here redundant? Or necessary?
<?php
if( $_POST ) {
// $_POST variables are set, do the stuff
} else {
// get php://input
$php_input = file_get_contents("php://input");
if( $php_input ) {
// php input exists, do the stuff
$php_postdata = json_decode($php_input);
// ...
} else {
// no $_POST and no php://input, so throw an error
echo 'Error';
exit();
}
}
?>
EDIT
I'm not expecting both $_POST and php://input at the same time; either one or the other. Use case is I get $_POST when hitting the PHP via jQuery and I get php://input when hitting the PHP via AngularJS.