How can I check if the Content-type of a POST request in PHP is either application/json or application/x-www-form-urlencoded?
I've tried using $_SERVER["CONTENT_TYPE"] and echo get_headers('url', 1)["Content-Type"] but neither of those work for me.
echo '<pre>';
print_r(getallheaders());
So
$allHeaders = getallheaders();
$contentType = $allHeaders['Content-Type'];
It's working below codes. You can try it
$headerArray = getallheaders();
$contentType = $headerArray['Content-Type'];
(Or)
$contentType = $_SERVER["CONTENT_TYPE"];
(Or)
$headerArray = apache_request_headers();
$contentType = $headerArray['Content-Type'];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With