How to hide display of PHP errors?

  • artcoder
  • Student
  • Student
  • User avatar
  • Posts: 89
  • Loc: United States

Post 3+ Months Ago

When I have PHP typos on live site, people is able to see the full detailed error message with full file path on the site. How do I suppress this display? Via Webhost? Or via PHP code?
  • camperjohn
  • Guru
  • Guru
  • User avatar
  • Posts: 1127
  • Loc: San Diego

Post 3+ Months Ago

http://php.net/error_reporting

error_reporting(0);
  • artcoder
  • Student
  • Student
  • User avatar
  • Posts: 89
  • Loc: United States

Post 3+ Months Ago

Hmmm. The documentation does say that this is how to turn off error reporting. But when purposely put in this syntax error...

Code: [ Select ]
<?php
error_reporting(0);
echo getTop(; ?>
  1. <?php
  2. error_reporting(0);
  3. echo getTop(; ?>


My browser is still displaying syntax error at line XX of file XXXXX.

Could it be that it also needs to be set in the PHP config?
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

Odd.

The problem is, you often don't have access to the php.ini file if you're using shared hosting.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

If you've got access to php.ini
Some shared hosting, such as Godaddy gives each account their own php.ini files (php.ini and php5.ini) where most settings can be altered.
Code: [ Select ]
; Print out errors (as a part of the output).  For production web sites,
; you're strongly encouraged to turn this feature off, and use error logging
; instead (see below).  Keeping display_errors enabled on a production web site
; may reveal security information to end users, such as file paths on your Web
; server, your database schema or other information.
 
display_errors = Off
  1. ; Print out errors (as a part of the output).  For production web sites,
  2. ; you're strongly encouraged to turn this feature off, and use error logging
  3. ; instead (see below).  Keeping display_errors enabled on a production web site
  4. ; may reveal security information to end users, such as file paths on your Web
  5. ; server, your database schema or other information.
  6.  
  7. display_errors = Off
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Just a silly question. Why are you not handling the errors in your code gracefully?
  • artcoder
  • Student
  • Student
  • User avatar
  • Posts: 89
  • Loc: United States

Post 3+ Months Ago

Thanks, altering the php.ini worked perfectly.

Rabid Dog wrote:
Just a silly question. Why are you not handling the errors in your code gracefully?

That's because I have not quite learned that yet. But I will soon.
  • Truce
  • Guru
  • Guru
  • Truce
  • Posts: 1477
  • Loc: Washington DC

Post 3+ Months Ago

The reason setting error reporting to 0 didn't work for your syntax error is because a syntax error occurs when the compiler encounters something that isn't correct. Since the compiler had the error, your code was never executed, and thus error reporting was left to your ini setting.

You should turn on error logging and keep up on the log. Otherwise you might find yourself in a worse situation than if errors were displayed.
  • artcoder
  • Student
  • Student
  • User avatar
  • Posts: 89
  • Loc: United States

Post 3+ Months Ago

Good explanation. Understood.

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 131 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.