1

Closed

$_SERVER variable HTTP_CONTENT_TYPE doesn't exist -- Still an Issue

description

Here is the correct way to solve it:
 
if ((isset($_SERVER['HTTP_CONTENT_TYPE']) && strpos($_SERVER['HTTP_CONTENT_TYPE'], 'application/json') !== 0)
|| (isset($_SERVER['CONTENT_TYPE']) && strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== 0))
{
header('HTTP/1.0 500 Internal Server Error');
throw new Exception('Wrong content-type, should be application/json');
}
Closed Apr 25, 2007 at 9:08 PM by SteveMarx

comments

SteveMarx wrote Apr 25, 2007 at 9:08 PM

How is that different from what I did?

wrote Apr 25, 2007 at 9:08 PM

bencornwell wrote Jun 25, 2007 at 1:33 PM

Hi Steve - just caught your presentation at ReMIX07 and thought I'd check out the phpmsajax project.

I hit the issue described above - it's actually a PHP5 -> PHP4 legacy issue. PHP5 (strict mode) will generate an error if the array index you're trying to access doesn't exist, while PHP4 (or PHP5 running a more forgiving error_reporting() setting) won't.

Further, the isset() probably isn't the best way to test this condition either - the best way I've come across is: if( array_key_exists( $_SERVER, 'CONTENT_TYPE') ) { //do something }

Happy to submit a patch - just let me know how :)

bencornwell wrote Jun 25, 2007 at 1:40 PM

actually - that should be

if( array_key_exists( 'CONTENT_TYPE', $_SERVER ) ) { //do something }

Standard argument ordering isn't one of PHP's strong points ;)

wrote Feb 13, 2013 at 5:36 PM

wrote May 15, 2013 at 11:27 PM