Forum Moderators: coopster

Message Too Old, No Replies

PHP in IMG as in <IMG SRC="/script.php?id=1">

What about error handling?

         

Cook

3:19 pm on Oct 17, 2004 (gmt 0)

10+ Year Member



Hi,
I have a need for a php script inside an IMG tag to generate an image on the fly:

<IMG SRC="/script.php?id=1">

This works ok. However to ensure stability and reliability, I am concerned about error handling. If something goes wrong in the php, how are errors reported? Just with a red cross in lieu of the image? From my tests, it appears so, and the php error handler does not catch any error, or at least does not generate any sort of error message in the browser.

I've not had any luck with searches on that matter so far. Has anyone some light to shed on this or similar experience to share? Thank you.

Cheers,
Cook

mincklerstraat

3:27 pm on Oct 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In this kind of case, since php is supposed to be generating an image, if no image is properly generated, or if the link is off, no message will be directly displayed in the browser (since the only output that this script.php has is referenced by <img src=, as an image).

You'd want to use a different kind of error handling with the image-producing file. You can use:
ini_set('log_errors', 1);
This will log php errors in the server's error log; or else you can use set_error_handler() and set a function that you write to make a log entry.

You can also use gd to print out error messages on the image itself; I've done this one too, and it's good for logical errors in the image-production script (only works if a valid image is actually produced). image_string() is what you'd be looking for, probably in some kind of combo with set_error_handler().

Cook

3:34 am on Oct 18, 2004 (gmt 0)

10+ Year Member



Thank you very much for this helpful reply mincklerstraat.
Cheers,
Cook