Forum Moderators: coopster

Message Too Old, No Replies

Catching Errors

         

Pico_Train

11:32 am on Jun 3, 2009 (gmt 0)

10+ Year Member



I run a pretty complex site for client. Occasionally there are going to be some errors that pop up. The problem is that I only get say error line 424, undefined offset $var[0].

The dynamic pages get called on $_POST and $_GET actions

Is there a way that I can say capture was the scenario was and email me the details? So for example:

page: filename
$_POST vars listed here if any
$_GET vars listed here if any

Thanks!

Damage

12:13 pm on Jun 3, 2009 (gmt 0)

10+ Year Member



Generally, if you use a "@" before any PHP expression, any error messages that might be generated by that expression will be ignored.

So, assuming line 424 in your code looks like this:

$a = $var[0];

You can change it to this:

$a = @$var[0];

And then you can check if $a really contains a value... if it doesn't - you know an error occurred.
For example:

if (!isset($a))
{
//Send the relevant information to yourself via e-mail.
...
}

You can also use error_get_last:

[php.net...]

As for e-mailing the data to yourself - check out PHP's mail function:

[php.net...]

dive into perl

1:02 pm on Jun 3, 2009 (gmt 0)

10+ Year Member



You could also define an error handling function with [uk3.php.net...] which then either emails the details to you, or logs the errors to an error file.

Pico_Train

1:52 pm on Jun 4, 2009 (gmt 0)

10+ Year Member



Yeah I' struggling here a bit.

Basically say I get an error, any error, I'd like it to mail me the error.

I know the mail function no problem at all. But how do I check if there is an error? Say I run the page and the code goes but there is an error in there, any error...

How do I check if there is an error?

if(isset($error))
{
message = '';

if(!empty$_POST))
{
foreach($_POST as $p)
{
$message .=$p."<br>";
}
}

if(!empty$_GET))
{
foreach($_GET as $g)
{
$message .=$g."<br>";
}
}
mail($recipient, $message, $headers,etc...);
}

Pico_Train

1:54 pm on Jun 4, 2009 (gmt 0)

10+ Year Member



I see the error_get_last(); function, should I maybe put that at the bottom of all my pages and if it's not empty, then send that stuff to myself that way?

Pico_Train

2:14 pm on Jun 4, 2009 (gmt 0)

10+ Year Member



Got it! error_get_last works nicely. Thanks for putting me on the right path!

Damage

5:38 pm on Jun 4, 2009 (gmt 0)

10+ Year Member



You're welcome :-)