InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more

Menu
  • Home
  • Sitemap

Python Programming Language Best Tutorials and Code Examples

Learn Python Right Now!
Home
PHP
Hiding Error Messages from Users in PHP
PHP

Hiding Error Messages from Users in PHP

InfinityCoder December 23, 2016

You don’t want PHP error messages to be visible to users.

Set the following values in your php.ini or web server configuration file:

1
2
display_errors =off
log_errors     =on

You can also set these values using ini_set() if you don’t have access to edit your server’s php.ini file:

1
2
ini_set('display_errors', 'off');
ini_set('log_errors', 'on');

These settings tell PHP not to display errors as HTML to the browser but to put them in the server’s error log.

When log_errors is set to on, error messages are written to the server’s error log.

If you want PHP errors to be written to a separate file, set the error_log configuration directive with the name of that file:

1
error_log = /var/log/php.error.log

or:

1
ini_set('error_log', '/var/log/php.error.log');

If error_log is set to syslog, PHP error messages are sent to the system logger using syslog(3) on Unix and to the Event Log on Windows.

If error_log is not set, error messages are sent to a default location, usually your web server’s error log file. (For the
command-line PHP program, the default error location is the standard error output stream.)
There are lots of error messages you want to show your users, such as telling them they’ve filled in a form incorrectly, but you should shield your users from internal errors that may reflect a problem with your code.

There are two reasons for this. First, these errors appear unprofessional (to expert users) and confusing (to novice users).

If something goes wrong when saving form input to a database, check the return code from the database query and display a message to your users apologizing and asking them to come back later.

Showing them a cryptic error message straight from PHP doesn’t inspire confidence in your website. Second, displaying these errors to users is a security risk.

Depending on your database and the type of error, the error message may contain information about how to log in
to your database or server and how it is structured.

Malicious users can use this information to mount an attack on your website.
For example, if your database server is down, and you attempt to connect to it with mysql_connect(), PHP generates the following warning:

1
2
3
<br>
<b>Warning</b>: Can't connect to MySQL server on 'db.example.com' (111) in
<b>/www/docroot/example.php</b> on line <b>3</b><br>

If this warning message is sent to a user’s browser, he learns that your database server is called db.example.com and can focus his cracking efforts on it.

Share
Tweet
Email
Prev Article
Next Article

Related Articles

Creating Methods Dynamically in PHP
You want to dynamically provide methods without explicitly defining them. …

Creating Methods Dynamically in PHP

Program: whereis in PHP
Although tools such as phpDocumentor provide quite detailed information about …

Program: whereis in PHP

About The Author

InfinityCoder
InfinityCoder

Leave a Reply

Cancel reply

Recent Tutorials InfinityQuest

  • Adding New Features to bash Using Loadable Built-ins in bash
    Adding New Features to bash Using Loadable …
    June 27, 2017 0
  • Getting to the Bottom of Things in bash
    Getting to the Bottom of Things in …
    June 27, 2017 0

Recent Comments

  • fer on Turning a Dictionary into XML in Python
  • mahesh on Turning a Dictionary into XML in Python

Categories

  • Bash
  • PHP
  • Python
  • Uncategorized

InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more

About Us

Start learning your desired programming language with InfinityQuest.com.

On our website you can access any tutorial that you want with video and code examples.

We are very happy and honored that InfinityQuest.com has been listed as a recommended learning website for students.

Popular Tags

binary data python CIDR convert string into datetime python create xml from dict python dictionary into xml python how to create xml with dict in Python how to write binary data in Python IP Address read binary data python tutorial string as date object python string to datetime python

Archives

  • June 2017
  • April 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
Copyright © 2021 InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more
Programming Tutorials | Sitemap