Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

PHP production server - turn on error messages

This question has been asked before in a more general way. I want to display error messages on a particular page on my production server, and I do not have access to the php.ini file. What is the best way to enable all errors and warnings on a particular PHP page on your production server?

I have tried ERROR_REPORTING(E_ALL);.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To enable errors, you must use error_reporting before the point where those are triggered (for example, at the beginning of your PHP script) :

error_reporting(E_ALL);

And to have the error displayed, you should configure display_errors :

ini_set('display_errors', 'On');

(This one should be disabled on a production server, which means you might have to enable it this way, even after having configured error_reporting)


Of course, all this can be encapsulated in an if block, to make sure only you can see the error messages -- especially if you are doing this on a live production website ; for instance :

if ($_SESSION['is_admin'])
{
    error_reporting(E_ALL);
    ini_set('display_errors', 'On');
}


And to get things a bit prettier, you might also want to configure html_errors :

ini_set('html_errors', 'On');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...