Simple error handling script not working - please help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mrbeepa
Forum Newbie
Posts: 1
Joined: Sun Jul 25, 2010 5:59 pm

Simple error handling script not working - please help!

Post by mrbeepa »

Hello I am trying to teach myself php using a couple books. I ran accross this error handling script and a small script to test it and it is not working?
Here is the error handling script:
(Note I have set the global variable $live to both TRUE & FALSE while test as it is supposed to deal with error handling differently if a site is live or not)

Code: Select all

<?
# Script handle.php
//flag variable for site status
$live = TRUE;
// create the error handler
function my_error_handler($e_number, $e_message, $e_file, $e_line, $e_vars){

global $live;
//build the error msg
$message = "An error occured in THE script '$e_file' on line $e_line :$e_message\n";
// append $e_vars to the $message
$message .= print_r($e_vars, 1);
	if($live){
		echo '<div>A system error occurred in a script. We apologize for the inconvenience.</div><br />';
	}else {
		echo '<div>' . $message . '</div><br />';
	}
}
set_error_handler('my_error_handler') or die('error handler not set!');
?>

]
and here is the script I am using to test it:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>OOPS!</title>
</head>
<body>
<?php 
include("handle.php") or die("could not open the file.");
echo $variable;
$result = 200/0;
?>
</body>
</html>
1) I am using uniform server so using localhost as my browser location for testing purposes.
2)I have edited the php.ini and tried adjusting the error reporting entries to different settings trying to test if they affect my script.
I have tried it with display_errors on & off and with the error reporting level set to E_ALL and also with that line rem'd out.

I am sure there are other scripts that are much better but please understand I am trying to learn so part of what I need to know is why this script isn't working??
I've copied and pasted the info so if I've missed syntax errors they should be visible but I haven't been able to recognize them at this point?
Thank you for all and any assistance you can give me. :banghead:
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Simple error handling script not working - please help!

Post by requinix »

What does "not working" mean?
Post Reply