0

In some scripts when i set http_response_code(401) or 500 when script is compiled it gaves a status code = 401 or 500 but in other scripts it gives me 200 OK even with an error in that script it will continue compiling it and returns 200 OK , I changed display_errors=On to Off and finally it gaves me the http_response_code(401) or 500 i writed in code but still executing the code , even if there is an error there it will execute all lines of the code after the error and efter the http_response_code(401)i think it must stop ? example :

<?php
    header( 'Access-Control-Allow-Credentials: true');
    header( "Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}" );
  $x = 5;
  http_response_code(500);
  setcookie("X",$x,time()+300,null,null,null,true);   
?> 

that code must return a 500 status code and not set that cookie but in some codes i have it does and gives 200 OK (this 200 OK status code problem is solved by changing display_errors=Off in php.ini but stops me from seeing errors messages),is that a bug or that how it works ?

DrNoob
  • 89
  • 1
  • 8
  • 2
    Does this answer your question? [Why does display\_errors change the HTTP status code?](https://stackoverflow.com/questions/11421240/why-does-display-errors-change-the-http-status-code) – vpzomtrrfrt Jun 17 '20 at 05:05
  • yes it makes some sense now i still think maybe its somehow bugged cause it works in some other scripts and on same script (sometimes) without having display_errors=off , thanks – DrNoob Jun 17 '20 at 07:07
  • so http_response_code(401) returns for me status code = 500 when i set display_errors=off , thats awful – DrNoob Jun 17 '20 at 07:33

0 Answers0