PHP header not shows custom message if code is 204

abaracedo

I'm writing and API and I throw and Exception that calls a method to compose the header to return. If there isn't content I throw an Exception with a custom message and code 204.

throw new Exception("my message", 204);

And the method that composes the header

if ($status_codes[$code] !== null) {
    $status_string = $code . ' ' . $status_codes[$code];
    header($_SERVER['SERVER_PROTOCOL'] . ' ' . $status_string, true, $code);

    if ($code != 200) die(json_encode(["code" => $code, "message" => $message]));

}

The problem is that when I use the code 204 I only show the status of the response that's a 204 No content but my message with the code is not shown. I tried with the code 400 and it shows the custom message.

Hanky Panky

The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.

RFC 2616

Need anymore words ? :)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

PHP header not shows custom message if code is 204

From Dev

Php include shows code

From Dev

MySQL no longer shows error message, only code

From Dev

php upload weirdness: Header shows up only

From Dev

Php code shows offset error

From Dev

PHP MySQL Success Message Always Shows

From Dev

PHP MySQL Success Message Always Shows

From Dev

PHP code shows after HTML code

From Dev

Integrate a Welcome message in header in functions.php

From Dev

Return message on window.onbeforeunload custom message didn't set. it shows always default message

From Dev

Wordpress shows PHP code instead of menu content

From Dev

PHP code after greater than (>) shows in HTML

From Dev

Instead of proccessing code of php it shows it as a comment

From Dev

Wordpress shows PHP code instead of menu content

From Dev

Some code shows as picture in php with Imagemagick

From Dev

ws:outbound-gateway custom interceptor with message header

From Dev

Using a custom defined variable in php header

From Dev

PHP EMail Script response message shows html tags

From Dev

My read message page shows multiple messages instead of one PHP

From Dev

Header in PHP overrides the HTTP Response code

From Dev

How to add custom code in mailers ? adding ruby code in @message variable

From Dev

Angular4 error message shows code which differs from the code that's supposed to be serving

From Dev

Query PHP output suddenly only shows code, no values?

From Dev

Php ide in java shows a line in the middle of the code window

From Dev

“php -f” doesn’t run code but only shows file contents

From Dev

Php code to include header.php not working correctly

From Dev

Returning HTTP Result Code 404 With a Custom Error Message

From Dev

Converting custom message authentication code from Java to JavaScript

From Dev

API Gateway Custom Authorizer: Control error message and code

Related Related

  1. 1

    PHP header not shows custom message if code is 204

  2. 2

    Php include shows code

  3. 3

    MySQL no longer shows error message, only code

  4. 4

    php upload weirdness: Header shows up only

  5. 5

    Php code shows offset error

  6. 6

    PHP MySQL Success Message Always Shows

  7. 7

    PHP MySQL Success Message Always Shows

  8. 8

    PHP code shows after HTML code

  9. 9

    Integrate a Welcome message in header in functions.php

  10. 10

    Return message on window.onbeforeunload custom message didn't set. it shows always default message

  11. 11

    Wordpress shows PHP code instead of menu content

  12. 12

    PHP code after greater than (>) shows in HTML

  13. 13

    Instead of proccessing code of php it shows it as a comment

  14. 14

    Wordpress shows PHP code instead of menu content

  15. 15

    Some code shows as picture in php with Imagemagick

  16. 16

    ws:outbound-gateway custom interceptor with message header

  17. 17

    Using a custom defined variable in php header

  18. 18

    PHP EMail Script response message shows html tags

  19. 19

    My read message page shows multiple messages instead of one PHP

  20. 20

    Header in PHP overrides the HTTP Response code

  21. 21

    How to add custom code in mailers ? adding ruby code in @message variable

  22. 22

    Angular4 error message shows code which differs from the code that's supposed to be serving

  23. 23

    Query PHP output suddenly only shows code, no values?

  24. 24

    Php ide in java shows a line in the middle of the code window

  25. 25

    “php -f” doesn’t run code but only shows file contents

  26. 26

    Php code to include header.php not working correctly

  27. 27

    Returning HTTP Result Code 404 With a Custom Error Message

  28. 28

    Converting custom message authentication code from Java to JavaScript

  29. 29

    API Gateway Custom Authorizer: Control error message and code

HotTag

Archive