I want to simulate an error 500 on a local server.

How is this done correctly?

I tried to just set the headers, but nothing was displayed in the browser.

  • So you do not send anything to the browser, that's empty. On the 500th, you can send a picture, for example, header('HTTP/1.1 500 Internal Server Error'); echo "<image src='$imageUrl' style='width: 100%' />"; header('HTTP/1.1 500 Internal Server Error'); echo "<image src='$imageUrl' style='width: 100%' />"; - it will be displayed. In the developer console, see, now your mistake is only there. - BOPOH
  • if the script is run from the console, it will return only igor @ igor-H81M-S2V: / var / www / trysome $ php -f error500.php <image src = ' joomlaworks.net/images/documentation/SIGPro_Settings_Closed.png ' style = ' Width: 100% '/> igor @ igor-H81M-S2V: / var / www / trysome $, there is no information about the error. Or am I doing something wrong? - Igor Kalamurda
  • To answer a question, add all the relevant code and error messages to the question itself. How to ask questions , how to create a brief, complete and reliable example. - Nick Volynkin
  • You did not understand, I meant the following: open a baruser (for example, Chrome), there you open the developer console (for chrome it opens on F12), in the console you open the "network" tab (or similar). After that open your page. The console will show the access to the server and the server response. - BOPOH

1 answer 1

Using the http_response_code function

 // например, http_response_code(500); // или http_response_code(404); 
  • Please as for a teapot))) I tried this function, I could not figure out how it works. This is what I was <? Php http_response_code (500); - Igor Kalamurda
  • @IgorKalamurda, you wanted to see the reaction of the browser, so open the console where you will see its reaction)) - Deonis
  • Through the browser opened, and through the console launched - the browser is clean, the console is clean. Put the glasses on me))) - Igor Kalamurda
  • Do not run through the console, but watch the result. Chrome will have something like this: Failed to load resource: the server responded with a status of 404 (Not Found) , in FF - GET site.com [HTTP / 1.1 404 Not Found 4ms] PS If you look at Chrome, tick " Preserve Log " - Deonis
  • one
    @Deonis, the vehicle does not know what console we are talking about, I wrote above how to get access to it, I hope to find it - BOPOH