Home arrow PHP arrow Page 10 - Time Is Money (part 2)

When Things Go Wrong - PHP

In this concluding article, explore the scripts which add andremove timesheet entries to the system, and get a crash course instatistics by using these entries to generate useful resource allocationand usage reports.

  1. Time Is Money (part 2)
  2. Getting Creative
  3. Split Personality
  4. In...
  5. ...And Out
  6. The Number Game
  7. Exercising Restraint
  8. The Big Picture...
  9. ...And The Little Brush Strokes
  10. When Things Go Wrong
  11. Happy Endings
By: The Disenchanted Developer, (c) Melonfire
Rating: starstarstarstarstar / 4
November 16, 2001

print this article


The last script - another extremely simple one - is the error handler, "error.php". If you look at the source code, you'll notice many links to this script, each one passing it a cryptic error code via the $ec variable. Very simply, "error.php" intercepts the variable and converts it to a human-readable error message, which is then displayed to the user.

<? // error.php - displays error messages based on error code $ec // includes include("config.php"); include("functions.php"); switch ($ec) { // login failure case 0: $message = "There was an error logging you in. <a href=index.html>Please try again.</a>"; break; // session problem case 1: $message = "There was an authentication error. Please <a href=index.html>log in</a> again."; break; // bad datestamp case 2: $message = "You selected an invalid date range. Please <a href=menu.php>try again</a>."; break; // default action default: $message = "There was an error performing the requested action. Please <a href=index.html>log in</a> again."; break; } ?> <html> <head> <basefont face="Verdana"> <style type="text/css"> TD {font-family: Verdana; font-size: smaller} </style> </head> <body bgcolor="White"> <? $title="Error!"; ?> <? include("header.inc.php"); ?> <? echo $message; ?> <? include("footer.inc.php"); ?> </body> </html>
Here's what it looks like.

Simple and elegant - not to mention flexible. Found a new error? No problem - assign it an error code and let "error.php" know.

>>> More PHP Articles          >>> More By The Disenchanted Developer, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: