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
427 views
in Technique[技术] by (71.8m points)

html - How to have PHP display errors? (I've added ini_set and error_reporting, but just gives 500 on errors)

So, I don't really have any errors in my current web page, but I want to be able to see an error when they pop up, instead of the HTTP 500 error page. I googled around a bit and thought adding these two lines would fix everything.

ini_set('display_errors', 'On');
error_reporting(E_ALL);

NOTE: I don't have access to the php.ini file, as I'm using my school account's server.

So I introduced a bug (no semicolon after $buggy) like so at the top of my page:

<?php 
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$buggy

$x = 4 + 2;
...

However, I just get a Server error:

"The website encountered an error while retrieving http://mywebpage.com/. It may be down for maintenance or configured incorrectly."

Any ideas?

EDIT:

I've reconfigured my code:

<?php 
include_once 'database/errorSettings.php';
?>
<?php 

$buggy // whoops
$x = 4 + 2;
...

errorSettings.php is the following:

<?php
    ini_set('display_errors', 'On');
    error_reporting(E_ALL);
?>

But it still doesn't work... wrong way to reconfigure?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

What you have is a parse error. Those are thrown before any code is executed. A PHP file needs to be parsed in its entirety before any code in it can be executed. If there's a parse error in the file where you're setting your error levels, they won't have taken effect by the time the error is thrown.

Either break your files up into smaller parts, like setting the error levels in one file and then includeing another file which contains the actual code (and errors), or set the error levels outside PHP using php.ini or .htaccess directives.


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

...