1

I am creating a simulation game (web service), and need to fake those error pages. As far as I know, and can see, there isn't a way to fake a 404, or 500 etc. Is this right? Are we able to do this programmatically?

I know I could just make a 404 page and redirect to it... But I'm trying to make it a little more realistic.

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
Arrow
  • 2,784
  • 8
  • 38
  • 61
  • define realistic. Its trivial to send back custom http response from a webpage. Most websites do send additional information with the 404 or 500 etc. – Keshi Jul 20 '12 at 03:23
  • Possible duplicate of [How to send 500 Internal Server Error error from a PHP script](http://stackoverflow.com/questions/4162223/how-to-send-500-internal-server-error-error-from-a-php-script) – i am me Nov 30 '15 at 19:31
  • Possible duplicate of [Simulate fake 404,500 Status Code to check frontend app behaviour](https://stackoverflow.com/questions/50923170/simulate-fake-404-500-status-code-to-check-frontend-app-behaviour) – Sachin Jain Jan 19 '22 at 09:17
  • Does this answer your question? [Simulate fake 404,500 Status Code to check frontend app behaviour](https://stackoverflow.com/questions/50923170/simulate-fake-404-500-status-code-to-check-frontend-app-behaviour) – Sachin Jain Jan 19 '22 at 09:37

3 Answers3

3

Returning a 404 or 500 status code to the browser (see your programming language's/framework's documentation for how) will send a real one instead of a fake one.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
1

Copy whatever page your server sends for those particular errors (or just read the existing files if you've specified them explicitly) and write that out, then send the right status code along with it. For example, in PHP:

header("HTTP/1.1 500 Internal Server Error");
Ry-
  • 218,210
  • 55
  • 464
  • 476
0

Here's how I'd do it using PHP:

<?php
    header('HTTP/ 404'); //So that the browser thinks it's a legitimate 404 error.
    @readfile($_SERVER['DOCUMENT_ROOT'] . '/404.html') or die('404 Not Found'); //Replace "/404.html" with your 404 page.
?>
FluorescentGreen5
  • 879
  • 11
  • 23