What is the purpose of using ErrorDocument in PHP and how does it work with different HTTP status codes?

The purpose of using ErrorDocument in PHP is to customize the error pages that are displayed when a specific HTTP status code is encountered. By using ErrorDocument, you can provide a more user-friendly and informative error message to the visitors of your website. It works by specifying the HTTP status code along with the custom error page that should be displayed when that code is triggered.

// Example of using ErrorDocument to handle 404 Not Found error
// Create a custom error page named 404.php

// In your .htaccess file, add the following line:
ErrorDocument 404 /404.php

// Now, when a 404 Not Found error occurs, the custom error page 404.php will be displayed to the user.