Jump to content

Exit on PHP error


ChenXiu
 Share

Recommended Posts

If my page has a PHP error, I want to immediately exit with the error displayed in my browser.
Because I'm on a shared server (no access to php.ini file, and NO error logs!) I have to have this on top of my page:
ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL);
However, I also need PHP to exit with the error message displayed.
(The reason is some of the scripts reload to another page and I only see a milisecond flash of error message.)

Thank you.

Link to comment
Share on other sites

Adding a try/catch or die to every single place that an error could potentially occur would probably be an exercise in futility. You say that your shared server has no error logs. You could try adding code to your page(s) to generate an error log.

Put this code somewhere so that it will be executed on any page load:

ini_set("log_errors", 1);
ini_set("error_log", "php-errors.log");

You could then have a separate bowser window open to the location of the error log and refresh it upon any page load to see what errors may have occurred.

Link to comment
Share on other sites

With the ini settings you are making the errors will display automatically.  Simply do the exit when you check for errors.   I don't think  you need to set the 'startup' setting since you are not doing any startup.

Link to comment
Share on other sites

2 hours ago, Psycho said:
ini_set("error_log", "php-errors.log");

Thank you, this will help!

The main problem I have is I have a javascript window.open -- the window opens and it flashes the error for a nanosecond and then reloads with correct html data. So I need to figure out what that error message was that only flashed for a nanosecond.

Regarding my error reporting code (e.g. "ini_set('display_errors', '1');"), I don't know how (or where) to put the "exit;" in there.

Link to comment
Share on other sites

You add error checking to things that matter.  If you are trying to open a file, check if you did.  Running a query? Check for the results.  Echo out an error message of your own and then exit.  Any errors from php that you have asked to see will now show up on their own.  You don't put the exit with the ini settings.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.