Webmaster Forum
Go Back   Webmaster Forums UK SEO SEM Webmaster Community Forum - UKWW > Web Design and Website Development > Programming > PHP Forum
Register FAQ Members List Downloads Calendar Today's Posts Webmaster Resources Webmaster Blogs

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-24-2007, 09:20 PM
Senior Member
 
Join Date: Feb 2007
Posts: 148
iTrader: 0 / 0%
Thanks: 0
Thanked 0 Times in 0 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
lala is on a distinguished road
Default Error handling

We struggle to come up with a decent error handling function. I thought that I use a global variable $live to easily make a switch from testing to live. I will keep the function in an include file.
I kind of got there to print a "user-friendly" message when the site is live, but it messes up the whole page layout. Don't how to print the error message in the content area. How would I adjust my error handler and what would I add to "<?php require_once $content; ?>"?

My error handler:
<?php
/*-- start output buffering--*/
ob_start();
/*-- live site --*/
$live=TRUE;
/*-- error handling function giving back error number, the actual message, the error file, the error line and the variables (what are variable in this context?) --*/
function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) {
/*-- make $live global --*/
global $live;
/*-- set error message for testing together --*/
$message="Error in file '$e_file' on line $e_line: $e_message\n";
$message.=print_r($e_vars,1);
/*-- error message for live site should not give any detail about problem, just an apology --*/
if($live){
$user="We apologise for the problems on this page...";
/*-- if there are error messages print the standard user message --*/
if ($message==0){echo $user;}else{
/*-- otherwise say 'hi there' --*/
echo ('');}
/*-- do it only once as user should not see the apology more than once --*/
exit();
} else {
/*-- if site is in testing print the acual error messages --*/
echo '<div class="error">'.$message.'</div><br/>';
}
}
ob_end_flush();
/*-- as everything is defined now, set the error handler, so it's ready to be used --*/
set_error_handler('my_error_handler');
?>

Also, in the bit "if ($message==0)" I would have thought that comparing $message to 1 would have printed the user-friendly error message (as I thought 1 means that there is one or more error message).


Any help appreciated.

Lala
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Closed Thread

Bookmarks

Webmaster Resources
UK WW SEO Tools
Find UK Hosts
 
The Forum Rules
Forum Rules - MUST READ
 
Site Of the Month
BizzFace
Nominate site of the month
 
Tag Cloud
a75-s229 laptop ac adapter apple ipod nano 4gb brand new cellphone digital camera dj mixer drupal earphones ecommerce edible oil electronics events in india for webmasters free social hosting free web space google analytical tool hosting hosting offer low cost iphone iphone 3g 16gb iphones laptops mdj's mobile phones motorola rokr e6 newbie new pioneercdj's nokia oil phones phpld plasma tv poineer prepaid phone card prepaid phone cards proxy social web hosting telecom links template design usb cable web hosting webmasters web space for free

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse error: syntax error Bagi Zoltán PHP Forum 3 11-25-2007 04:30 PM
Error gone? temi General Webmaster Talk 3 09-26-2007 12:15 PM
Installation - SQL error northernwc Boss Cart Installation Help 12 09-19-2006 10:43 AM
661 error jacky820 iG Shop 3 12-17-2004 01:52 AM
Fatal error pteixeira iG Shop 1 04-10-2004 01:36 AM


All times are GMT. The time now is 05:36 PM.

UK Webmaster World Forums - Internet marketing, web development, domain names, SEO contest and discussuons.
Subscribe to our feeds   Subscribe to our feeds

Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151