2
votes

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.

1
$_SERVER["CONTENT_TYPE"] must work - Umair Ayub

1 Answers

4
votes
echo '<pre>';
print_r(getallheaders());

So

$allHeaders = getallheaders();
$contentType = $allHeaders['Content-Type'];