How to Remove On-Page Errors in PHP

On-page errors, warnings, and notices are default in PHP for convenient debugging. However, while deploying on production, it is not a good practice to show on-page errors.

On-page errors may provide loopholes of our website to hackers. Even more, it can break our website’s front end design.

Here we are going to learn how to disable on-page errors, warnings, and notices in PHP.

PHP Remove On-Page Errors, Warnings, Notices

There are three methods to remove on-page errors in PHP.

  1. Remove on Specific PHP Page
  2. Remove on the Whole Project .HTACCESS File
  3. Remove on HOST via php.ini File

Method 1: Remove on Specific PHP Page

This method is to disable errors on a specific page in our PHP website. Insert below PHP code at the top of the PHP page to remove errors, warnings, and notices from that page.

error_reporting(0);

Method 2: Remove on the Whole Project .HTACCESS File

This method helps remove errors, warnings, and notices from the whole PHP project. We need to insert the below code into our projects.HTACCESS file.

php_flag display_errors = Off

Method 3: Remove on HOST via php.ini File

This method is used to apply when we have to remove errors, warnings, and notices from the whole host machine, which will affect all projects running on that host server.

Just go to the php.ini file in your host machine and turn off the display_errors flag.

display_errors = Off

Read Also: How to Echo New Line in PHP

Conclusion

Here we have discussed every method to remove or disable on-page errors, warnings, and notices in PHP projects.

I hope this post will help you to resolve your problem.

Happy Coding πŸ™‚

Leave a Reply

Your email address will not be published. Required fields are marked *

Read previous post:
Default Value in select menu in HTML Using JavaScript
How to Set Selected Value of Dropdown in JavaScript

In this article, we are going to learn how to set selected value of dropdown in JavaScript for dynamic dropdown...

Close